So, when some goes to mysite com/this-is-a-sef-url it uses 'this-is-a-sef-url' to get that blog post.
Anyway here is the function I use to convert:
Code: Select all
function convert_to_sef_url($str)
{
$str = str_replace("'","",$str); //replace ' with nothing
$str = str_replace('"',"",$str); //replace " with nothing
$str = preg_replace("/[^a-zA-Z0-9_-]/","-", $str); //convert non alphanumeric and non - _ to -
$str = preg_replace ( "/-+/" , "-" , $str ); //convert multiple dashes to a single dash
$str = strtolower($str);
return $str;
}I want to make sure only a-z and A-Z and 0-9 and underscores and dashes are the only things allowed in the sef url and no multiple dashes. I think I've got everything but a fresh pair of eyes is always nice.