- utf8_decode: documentation ( source)
- strtr: documentation ( source)
- trim: documentation ( source)
- preg_replace: documentation ( source)
<?php
function slugify($text)
{
$text = trim($text);
$text = strtr(
utf8_decode($text), "\xe1\xc1\xe0\xc0\xe2\xc2\xe4\xc4\xe3\xc3\xe5\xc5" .
"\xaa\xe7\xc7\xe9\xc9\xe8\xc8\xea\xca\xeb\xcb\xed" .
"\xcd\xec\xcc\xee\xce\xef\xcf\xf1\xd1\xf3\xd3\xf2" .
"\xd2\xf4\xd4\xf6\xd6\xf5\xd5\x8\xd8\xba\xf0\xfa\xda" .
"\xf9\xd9\xfb\xdb\xfc\xdc\xfd\xdd\xff\xe6\xc6\xdf\xf8", "aAaAaAaAaAaAacCeEeEeEeEiIiIiIiInNo" .
"OoOoOoOoOoOoouUuUuUuUyYyaAso"
);
$text = preg_replace('![^a-z0-9]!i', ' ', $text);
$text = preg_replace('!\s{2,}!', ' ', $text);
$text = preg_replace('!\s!', '_', $text);
return $text;
}
for($i=0;$i<=10;$i++)
slugify( '"6รจ1es(r51-_dih56bs1z"6bt' );