1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| function clean_string($string) {
$string = strtolower(trim($string));
// escape first the unescaped elements by mb_convert_encoding ('\'', '"', and '&')
$string = preg_replace("#[ ,.;:'%&()\-\"]+#", "-", $string);
$string = mb_convert_encoding($string, 'HTML-ENTITIES', 'UTF-8');
// replace accents
$string = preg_replace(array('/ß/', '/&(..)lig;/', '/&([aouAOU])uml;/', '/&(.)[^;]*;/'), array('ss', "$1", "$1".'e', "$1"), $string);
// replace all special characters except '-'
$string = preg_replace("/[^a-z0-9-]/i", '-', $string);
return $string;
} |
Partager