preg_replace(), removing string containing '+' char
I am 开发者_JS百科having an issue removing "%3Cbr+%2F%3E" from my string using the preg_replace function. My assumption is that the '+' char is being interpreted incorrectly. Here my code:
$address = preg_replace('/%3Cbr+%2F%3E/', '', urlencode($address));
Thanks as always!
The +
is a special character in regular expression. It is a quantifier and means that the preceding expression can be repeated one or more times.
Escape it with \+
and it should work:
$address = preg_replace('/%3Cbr\\+%2F%3E/', '', urlencode($address));
But since you’re replacing a static expression, you could also use str_replace
:
$address = str_replace('%3Cbr+%2F%3E', '', urlencode($address));
精彩评论