我想像wordpress一样生成页面,类别等的slu .. 让我有页面标题:“我的页面标题” 然后转义空格和特殊字符并生成类似“my-page-title” 怎么做
答案 0 :(得分:1)
这是生成slugs的函数
function slug($var){
$seoname = preg_replace('/\%/',' percentage',$var);
$seoname = preg_replace('/\@/',' at ',$seoname);
$seoname = preg_replace('/\&/',' and ',$seoname);
$seoname = preg_replace('/\s[\s]+/','-',$seoname); // Strip off multiple spaces
$seoname = preg_replace('/[\s\W]+/','-',$seoname); // Strip off spaces and non-alpha-numeric
$seoname = preg_replace('/^[\-]+/','',$seoname); // Strip off the starting hyphens
$seoname = preg_replace('/[\-]+$/','',$seoname); // // Strip off the ending hyphens
$seoname = strtolower($seoname);
return $seoname;
}