This function will turn any string into a safe string usable in a URI.
function dirify($s) {
$s = convert_high_ascii($s);
$s = strtolower($s);
$s = strip_tags($s);
$s = preg_replace('!&[^;\s]+;!','',$s);
$s = preg_replace('![^\w\s.]!','',$s);
$s = preg_replace('!\s+!','-',$s);
return $s;
}
function convert_high_ascii($s) {
$HighASCII = array(
"!\xc0!" => 'A',
"!\xe0!" => 'a',
"!\xc1!" => 'A',
"!\xe1!" => 'a',
"!\xc2!" => 'A',
"!\xe2!" => 'a',
"!\xc4!" => 'Ae',
"!\xe4!" => 'ae',
"!\xc3!" => 'A',
"!\xe3!" => 'a',
"!\xc8!" => 'E',
"!\xe8!" => 'e',
"!\xc9!" => 'E',
"!\xe9!" => 'e',
"!\xca!" => 'E',
"!\xea!" => 'e',
"!\xcb!" => 'Ee',
"!\xeb!" => 'ee',
"!\xcc!" => 'I',
"!\xec!" => 'i',
"!\xcd!" => 'I',
"!\xed!" => 'i',
"!\xce!" => 'I',
"!\xee!" => 'i',
"!\xcf!" => 'Ie',
"!\xef!" => 'ie',
"!\xd2!" => 'O',
"!\xf2!" => 'o',
"!\xd3!" => 'O',
"!\xf3!" => 'o',
"!\xd4!" => 'O',
"!\xf4!" => 'o',
"!\xd6!" => 'Oe',
"!\xf6!" => 'oe',
"!\xd5!" => 'O',
"!\xf5!" => 'o',
"!\xd8!" => 'Oe',
"!\xf8!" => 'oe',
"!\xd9!" => 'U',
"!\xf9!" => 'u',
"!\xda!" => 'U',
"!\xfa!" => 'u',
"!\xdb!" => 'U',
"!\xfb!" => 'u',
"!\xdc!" => 'Ue',
"!\xfc!" => 'ue',
"!\xc7!" => 'C',
"!\xe7!" => 'c',
"!\xd1!" => 'N',
"!\xf1!" => 'n',
"!\xdf!" => 'ss'
);
$find = array_keys($HighASCII);
$replace = array_values($HighASCII);
$s = preg_replace($find,$replace,$s);
return $s;
}