[eluser]codex[/eluser]
[quote author="inparo" date="1211055482"]Here's my take on the thing. It's a little shorter and deals with some exceptions. Not tested though, so no guarantees
.
Code:
// This way we don't have to mess with uppercase the rest of the time
$s = strtolower(htmlentities($s));
// We don't need to capture the second group, so I made it optional || added slash for oslash
$s = preg_replace ('/&([a-z])(?:uml|acute|grave|circ|tilde|cedil|ring|slash);/', '$1', $s);
// Weird characters that don't get caught above - also includes ðand þ, but I don't know what the best replacement for those would be.
// While we're at it, we'll also get the http
$s = str_replace( array('ß', 'æ', 'http://'), array('ss', 'ae', ''), $s);
$s = html_entity_decode($s);
// Normalize multiple spaces, dashes, and underscores
$s = preg_replace( array('/\s+/', '/-+/', '/_+/'), '_', $s);
// I've added a space here
$s = preg_replace('/[^a-z 0-9_-]/', '', $s);
return $s;
[/quote]
That works indeed. It's not spectacularly shorter (which I hoped was possible), but you shaved off a few bits, which is always good. Plus I learned something new in the process. So thank you!