1

我尝试更换

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 中删除最后一个“_”

4

1 回答 1

1

尝试这个 :

 <a href="<?php echo $row->id;?>/
 <?=trim(preg_replace('#[^\w\-]+#','_', strtolower($row->showTitle())), '_')?>.html"> 

它将删除任何尾随下划线。

于 2012-05-07T13:22:14.237 回答