得到json_encode不转义html实体 [英] getting json_encode to not escape html entities
问题描述
我从我的PHP服务器发送 json_encoded
数据到iPhone应用程序。包含html实体的字符串,如'&'
由 json_encode
转义,并作为& ; amp;
。
I send json_encoded
data from my PHP server to iPhone app. Strings containing html entities, like '&'
are escaped by json_encode
and sent as &
.
我想做两件事之一:
-
make
json_encode
不转义html实体。 Doc说正常模式不应该逃避它,但它不适合我。任何想法?
make
json_encode
not escape html entities. Doc says 'normal' mode shouldn't escape it but it doesn't work for me. Any ideas?
使iPhone应用程序可以廉价地转义html实体。我现在想到的唯一方法是调用一个非常昂贵的 XML / HTML解析器
。任何更便宜的建议?
make the iPhone app un-escape html entities cheaply. The only way I can think of doing it now involves spinning up a XML/HTML parser
which is very expensive. Any cheaper suggestions?
谢谢!
推荐答案
PHP 5.3和PHP 5.2都不会触及HTML实体。
Neither PHP 5.3 nor PHP 5.2 touch the HTML entities.
您可以 test ,并附上以下代码:
You can test this with the following code:
<?php
header("Content-type: text/plain"); //makes sure entities are not interpreted
$s = 'A string with & ۸ entities';
echo json_encode($s);
你会看到PHP做的唯一的事情是在字符串周围添加双引号。
You'll see the only thing PHP does is to add double quotes around the string.
这篇关于得到json_encode不转义html实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!