我将这个 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;
}