Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My webpage display ' and not '

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 ?

like image 745
François MENTEC Avatar asked Sep 05 '25 03:09

François MENTEC


2 Answers

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.

like image 90
Fenton Avatar answered Sep 07 '25 19:09

Fenton


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

like image 34
Pedro Lobito Avatar answered Sep 07 '25 20:09

Pedro Lobito