ワードプレスのようにページやカテゴリなどのスラッグを生成したいので、ページタイトルを付けましょう:「マイページタイトル」次に、空白と特殊文字をエスケープして、「マイページタイトル」のように生成します。
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 に答える