• 不断学习才有回报,学无止境!

PHP 生成友好URL 【用于SEO】

PHP技术和开发 箭翎 1526次浏览 0个评论 扫描二维码

public function friendlyURL($string, $replacement = ‘-‘) {
$map = array(
‘/à|á|?|?|?/’ => ‘a’,
‘/è|é|ê|?|?/’ => ‘e’,
‘/ì|í|?/’ => ‘i’,
‘/ò|ó|?|?/’ => ‘o’,
‘/ù|ú|?|?/’ => ‘u’,
‘/?|?/’ => ‘c’,
‘/?|ň/’ => ‘n’,
‘/?/’ => ‘l’,
‘/?/’ => ‘y’,
‘/?/’ => ‘t’,
‘/?/’ => ‘z’,
‘/?/’ => ‘s’,
‘/?/’ => ‘ae’,
‘/?/’ => ‘oe’,
‘/ü/’ => ‘ue’,
‘/?/’ => ‘Ae’,
‘/?/’ => ‘Ue’,
‘/?/’ => ‘Oe’,
‘/?/’ => ‘ss’,
‘/ /’=>’ ‘,
‘/ /’=>”,
‘/~|·|!|@|#|¥|%|…|&|×|(|)|-|\+|=|『|【|』|】|、|:|;|“|”|’|《|,|》|。|?|\/|—|_|‘|:|√|<|°|丶/’=>’ ‘,
‘/[^\w\s\x80-\xff]/’ => ‘ ‘,
‘/\\s+/’ => $replacement
);

$string = preg_replace(array_keys($map), array_values($map), $string);
$string = preg_replace(‘/\\s+/’,$replacement, strtolower($string));
$string = trim($string,$replacement);
return $string;
}


箭翎 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明PHP 生成友好URL 【用于SEO】
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址