str_replace with apostrophe [closed]
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.
精彩评论