I have a php script which return a JSON, and a js function which parse this JSON. In my php I did a htmlspecialchars but when I display value in my webpage ' isn't replace by ' same for "
any idea ?
If you are seeing ' on the page, you have probably double-encoded your string somewhere along the lines.
Encoding the string the first time changes ' to '.
Encoding the string a second time changes ' to '.
The result of this is that you see the code, not the char - as the web page converts the & to & visually, and ignores the rest.
Use html_entity_decode() with ENT_QUOTES
$string = "test '";
echo html_entity_decode($string, ENT_QUOTES);
Output:
test '
DEMO http://ideone.com/pZdJOa
read more about html_entity_decode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With