开发者

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜