简体   繁体   中英

PHP remove special character '%' from string

I would like to remove '%'

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

Any suggestions? Thanks

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

str_replace lets you specify multiple replacements, as above. Not sure what your wanted to replace % with so I put &#37; which is the HTML-escaped symbole for % .

Use preg_replace instead with Regular Expression

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

Learn about preg_replace : http://php.net/manual/en/function.preg-replace.php

Learn about Regular Expression : http://www.regular-expressions.info/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM