/** method slugify
*
* cleans up a string such as a page title
* so it becomes a readable valid url
*
* @param STR a string
* @return STR a url friendly slug
**/
function slugifyAlnum( $str ){
$str = preg_replace('#[^0-9a-z]#i', ' ', $str ); // allow letter and numbers only
$str = preg_replace('#( ){2,}#', ' ', $str ); // rm adjacent spaces
return strtolower( str_replace( ' ', '-', $str ) ); // slugify
}
Funny, I was working on this today, I trim it before sending it here, this func is for when Users are permitted to create a page title which you want to use to create a slug for mod_rewrite etc.
Allow for usual f-ups like more than one space, sticking non-alnum chars in it etc