2012-05-07 40 views
1

林試圖取代的preg_replace特殊字符

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"> 

$按行> showTitle()就像冠軍New New(2011)

,但問題是,因爲我的鏈接現在看起來是這樣

http://site.com/13/new_new_2011_.html 

我需要最後去掉 「_」 從URL _.html

+0

你必須用_ AND \替換\ s(空格)(用'' – Onheiron

回答

1

試試這個:

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

它將刪除任何尾隨的下劃線。

+0

修剪啊..這是工作..謝謝 –