如何将PHP变量从"My company & My Name“转换为"my-company-my-name"?
我需要让它全部小写,删除所有特殊字符,并用破折号替换空格。
发布于 2012-07-04 21:56:27
此函数将创建SEO友好的字符串
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;
}应该没问题:)
https://stackoverflow.com/questions/11330480
复制相似问题