1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| function enleve_accents($chaine) {
$reg = '/&(.)(acute|grave|circ|uml|cedil|ring|tilde|slash);/';
return preg_replace($reg, '\1', htmlentities($chaine));
}
function suppr_speciaux($chaine) {
$reg = '|(&[a-zA-Z0-9]*;)|U';
return preg_replace($reg, '-', $chaine);
}
$texte = strtolower($texte);
$reg = '|([^a-z0-9]+)|';
$texte = preg_replace($reg, '-', $texte);
$texte = trim($texte, '-');
function is_utf8($string) {
return !strlen(
preg_replace(
',[\x09\x0A\x0D\x20-\x7E]' # ASCII
. '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte
. '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs
. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte
. '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates
. '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3
. '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15
. '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16
. ',sS',
'', $string));
}
function nettoie_url($texte) {
if(is_utf8($texte))
$texte = utf8_decode($texte);
$texte = strtolower(suppr_speciaux(enleve_accents($texte)));
$reg = '|([^a-z0-9]+)|';
$texte = preg_replace($reg, '-', $texte);
return trim($texte, '-');
} |
Partager