function makeUrlSafeTitle($v_title) { $title= strtolower($v_title); $len = strlen($title); //change all none url chars to spaces for($i=0;$i<$len;$i++) { $letter = substr($title, $i, 1); preg_match('/[-0-9a-z]/', $letter, $matches); $spaceString .= (preg_match('/[-0-9a-z]/', $letter)) ? $letter : " "; } //replace all the spaces and excess spaces with one of these - $newstring = preg_replace('/\s\s+/', '-', $spaceString); $newstring = preg_replace('/ /', '-', $newstring); return $newstring; }