PHP从字符串中删除特殊字符'%'

时间:2015-12-11 16:19:59

标签: php string replace special-characters

我想删除'%'

echo '<a href="/coupon/'.$post->slug.'/'.$dcount.'/'.strtolower(str_replace(' ','-', $drow['title'])).'" target="_blank">';

有什么建议吗?感谢

2 个答案:

答案 0 :(得分:4)

str_replace([' ','%'], ['-','&#37;'], $drow['title']);

str_replace可让您指定多个替换,如上所述。不确定您要替换%的内容,因此我将&#37;放置为%的HTML转义符号。

答案 1 :(得分:2)

使用preg_replace代替正则表达式

preg_replace('/[ %]/','-', $drow['title']))

了解preg_replacehttp://php.net/manual/en/function.preg-replace.php

了解正则表达式:http://www.regular-expressions.info/