【发布时间】:2018-11-24 21:10:34
【问题描述】:
这是我的slugify 函数:
function slugify($text) {
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
$text = trim($text, '-');
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text = mb_strtolower($text, 'UTF-8');
$text = preg_replace('~[^-\w]+~', '', $text);
if(empty($text)) return 'n-a';
return $text;
}
这是测试:
echo slugify("españa");
在我的开发服务器中,结果是:
- 西班牙文
在我的生产服务器中,结果是:
- espaa
我确定这与字符集编码有关,但两台服务器都将UTF-8 设为default_charset。我还能错过什么?有任何想法吗?
【问题讨论】:
标签: php character-encoding preg-replace slugify