开发者

str_replace with apostrophe [closed]

开发者 https://www.devze.com 2023-04-03 18:10 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly appli开发者_如何转开发cable, visit the help center. Closed 10 years ago.

I have the following word:

d\'b

and when I do the following:

$test = str_replace(array("\\", "'"), "", "d\'b");

the outcome is:

d'b

Any idea why the apostrophe is not being replaced?


Sorry everyone - my bad -.-

The string I had being posted through a form was already being passed through htmlentities so the only thing I had to do was:

 str_replace("'", "", $variable);

I didn't realize it because when echoing the variable, it was being converted to the apostrophe


Try this:

$test = str_replace(array("\\'", "'"), "", "d\'b");

Tested here, seems to work well.


try this one:

$test = str_replace(array("\\", "'"), "", htmlspecialchars("d\'b", ENT_QUOTES));

May be it can help you.


Try to escape the backslash.. this worked for me

$test = str_replace(array("\\'", "'"), "", "d\'b"); 

Edit: pasted the wrong code.

0

精彩评论

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

关注公众号