【发布时间】:2012-05-07 13:19:54
【问题描述】:
我尝试替换
http://site.com/13/new new (2011).html
到
http://site.com/13/new_new_2011.html
这是我的代码,
<a href="<?php echo $row->id;?>/<?=preg_replace('#[^\w\-]+#','_', strtolower($row->showTitle()))?>.html">
$row->showTitle() 是一个类似于 New New (2011)
的标题但问题是因为我的链接现在看起来像这样
http://site.com/13/new_new_2011_.html
我需要从 url _.html 中删除最后一个“_”
【问题讨论】:
-
您必须将 \s(空格)替换为 _ AND ( 替换为 ''
标签: php regex preg-replace