我有一个将 URL 转换为 SEO 友好 URL 的 PHP 函数:
function seo_url($input){
$input = str_replace(array("'", "-"), "", $input); //remove single quote and dash
$input = mb_convert_case($input, MB_CASE_LOWER, "UTF-8"); //convert to lowercase
$input = preg_replace("#[^a-zA-Z0-9]+#", "-", $input); //replace everything non an with dashes
$input = preg_replace("#(-){2,}#", "$1", $input); //replace multiple dashes with one
$input = trim($input, "-"); //trim dashes from beginning and end of string if any
return $input;
}
我知道 SEO 对 javascript 中的 URL 执行此操作毫无意义,但为了保持一致性,我希望 URL 在我的应用程序中显示相同。有没有人在javascript中有方便的功能?:]