Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the HTML entities are getting displayed on iPhone/iPhone simulator even after removing them using PHP?

I'm sending a JSON encoded response to the request coming from iPhone. In few of the values some HTML entities are present. I tried using stripslashes() and html_entity_decode() on such values. In browser I'm able to get the proper JSON response i.e. without these HTML entities but when the same response is seen on iPhone or iPhone simulator the HTML entities displayed again.

How should I resolve this issue? Can someone please help?

If you wan I can provide you the necessary code.

Thanks.

like image 589
PHPLover Avatar asked Feb 06 '15 13:02

PHPLover


2 Answers

What about using http://php.net/manual/en/function.strip-tags.php?

This function tries to return a string with all NULL bytes, HTML and PHP tags stripped from a given str

like image 57
Andrii Mishchenko Avatar answered Oct 16 '22 23:10

Andrii Mishchenko


in PHP

<?php
header('Content-Type: application/json');
echo json_encode(array('test' => html_entity_decode("Hello &#8211; World", ENT_COMPAT, 'UTF-8')));

Output:

{"test":"Hello \u2013 World"}

in JS:

var o = jQuery.parseJSON('{"test":"Hello \u2013 World"}');
alert( o.test );

Output:

Hello – World
like image 22
Simone Nigro Avatar answered Oct 16 '22 23:10

Simone Nigro