gpt4 book ai didi

php - 如何生成 SEF slugs 或 url

转载 作者:行者123 更新时间:2023-11-29 14:12:03 26 4
gpt4 key购买 nike

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

最佳答案

这是生成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;
}

关于php - 如何生成 SEF slugs 或 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13330092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com