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 ?
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 ?
3 Answers
Reset to default 10If 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
When you do use htmlspecialchars
" "'" (single quote) becomes '''
(or '
) "
Read the PHP Manual.
htmlspecialchars()
in the first place? The usual reason for that is so that you see the literal HTML, instead of getting it parsed. – Barmar Commented Apr 28, 2015 at 20:02json_encode()
shouldn't create an object instead of a value. You REALLY need to show your code for us to help you. – Barmar Commented Apr 28, 2015 at 20:17