【发布时间】:2018-04-16 15:49:44
【问题描述】:
我将这个 PHP 函数用于 SEO 网址。它适用于拉丁词,但我的网址是西里尔字母。此正则表达式 - /[^a-z0-9_\s-]/ 不适用于西里尔字符,请帮助我使其适用于非拉丁字符。
function seoUrl($string) {
// Lower case everything
$string = strtolower($string);
// Make alphanumeric (removes all other characters)
$string = preg_replace('/[^a-z0-9_\s-]/', '', $string);
// Clean up multiple dashes or whitespaces
$string = preg_replace('/[\s-]+/', ' ', $string);
// Convert whitespaces and underscore to dash
$string = preg_replace('/[\s_]/', '-', $string);
return $string;
}
【问题讨论】:
-
范围:
U+0400–U+04FF -
谢谢,雷沃!这对我有用!
-
请务必使用
mb_strtolower而不是strtolower