这个函数用于创建URL蛞蝓:PHP代码字符串替换特殊字符删除字符
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
不替换字符,如:
ľščťýžťžýéíáý
喜欢的东西:
lsctyztzyeiay
而是,它完全消除他们
所以这个字符串:
asdf 1234 3 ľščťlkiop
成为
asdf-1234-3-lkiop
代替:
asdf-1234-3-lsctlkiop
任何想法是什么导致非英文字符消失以及如何将它们转换为英文变体?
这可以帮助你http://stackoverflow.com/a/2729224/4949388,否则,你可以试试这个http://stackoverflow.com/a/10064701/4949388 –