0

我想像 wordpress 一样生成页面、类别等的 slug 让我有页面标题:“我的页面标题”然后转义空格和特殊字符并生成像“my-page-title” 怎么做

4

1 回答 1

1

这是生成蛞蝓的功能

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;
}
于 2012-11-11T09:56:10.060 回答