将页面标题中的双连字符替换为单连字符
我有这样的页面标题:
$pageTitle = "<title>site - {$cat} - {$q} - {$prod} - {$prodName}</title>";
$pageTitle = str_replace(' - - ', ' - ', $pageTitle);
echo $pageTitle;
有时这会回显这样的页面标题:
<title>site - SportingGoods - Airbed - - SportingGoods</title>
当发生这种情况并且其中一个变量为空时,我想用一个连字符删除空的双连字符。我以为像 str_replace 这样的东西在这里可以工作,但事实并非如此。
提前致谢。
I have page titles like this:
$pageTitle = "<title>site - {$cat} - {$q} - {$prod} - {$prodName}</title>";
$pageTitle = str_replace(' - - ', ' - ', $pageTitle);
echo $pageTitle;
Sometimes this echos page titles like this:
<title>site - SportingGoods - Airbed - - SportingGoods</title>
When this happens and one of the vars is empty I want to remove the empty the double hyphen with a single one. I thought something like str_replace would work here but it doesn't.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当其中一个为空时,连字符之间将有两个空格(不是一个):
When one is empty you'll have two spaces (not one) between the hyphens:
要解决完整的问题,请使用以下命令:
To solve the complete problem use this: