【发布时间】:2017-06-11 15:46:47
【问题描述】:
我有一个大的多维数组,其中有多个字符串值,其中包含带有 html 标记和属性的字符串。
但是当我使用json_encode 时,我得到的输出有一些被删除的标签。
这是我在单独文件上尝试过的示例,以确定这是否真的是 json 编码的问题,结果证明我是对的。
<?php
$var = array(
"type" => "<p style=\"text-align: center;\">sfds</p>"
);
$encoded = json_encode($var);
echo '<pre>';
print_r($encoded);
遇到这种情况怎么办??
这是我从示例中得到的结果。
{"type":"
sfds<\/p>"}
这是我从多维数组中得到的结果。
{"data":[{"type":"columns","data":{"columns":[{"width":6,"blocks":[]},{"width":6,"blocks":[]}],"preset":"columns-6-6"}},{"type":"columns","data":{"columns":[{"width":6,"blocks":[{"type":"heading","data":{"text":"
I am the Heading<\/p>","mce_0":"
I am the Heading<\/p>"}},{"type":"heading","data":{"text":"
sfds<\/p>","mce_1":"
sfds<\/p>"}}]},{"width":6,"blocks":[{"type":"text","data":{"text":"
\n
Im Text<\/div>\n<\/div>","mce_2":"
\n
Im Text<\/div>\n<\/div>"}}]}],"preset":"columns-6-6"}},{"type":"text","data":{"text":"
\n
Im just a text<\/div>\n<\/div>","mce_3":"
\n
Im just a text<\/div>\n<\/div>"}}]}
=-=-=-=-=-=-
更新:生成的我尝试编码的数组变量的 var_dump 的 HTML 源代码。
<pre> after set2_decode:<br>array(1) {
["data"]=>
array(3) {
[0]=>
array(2) {
["type"]=>
string(7) "columns"
["data"]=>
array(2) {
["columns"]=>
array(2) {
[0]=>
array(2) {
["width"]=>
int(6)
["blocks"]=>
array(0) {
}
}
[1]=>
array(2) {
["width"]=>
int(6)
["blocks"]=>
array(0) {
}
}
}
["preset"]=>
string(11) "columns-6-6"
}
}
[1]=>
array(2) {
["type"]=>
string(7) "columns"
["data"]=>
array(2) {
["columns"]=>
array(2) {
[0]=>
array(2) {
["width"]=>
int(6)
["blocks"]=>
array(2) {
[0]=>
array(2) {
["type"]=>
string(7) "heading"
["data"]=>
array(2) {
["text"]=>
string(23) "<p>I am the Heading</p>"
["mce_0"]=>
string(23) "<p>I am the Heading</p>"
}
}
[1]=>
array(2) {
["type"]=>
string(7) "heading"
["data"]=>
array(2) {
["text"]=>
string(39) "<p style="text-align: center;">sfds</p>"
["mce_1"]=>
string(39) "<p style="text-align: center;">sfds</p>"
}
}
}
}
[1]=>
array(2) {
["width"]=>
int(6)
["blocks"]=>
array(1) {
[0]=>
array(2) {
["type"]=>
string(4) "text"
["data"]=>
array(2) {
["text"]=>
string(59) "<div>
<div style="text-align: center;">Im Text</div>
</div>"
["mce_2"]=>
string(59) "<div>
<div style="text-align: center;">Im Text</div>
</div>"
}
}
}
}
}
["preset"]=>
string(11) "columns-6-6"
}
}
[2]=>
array(2) {
["type"]=>
string(4) "text"
["data"]=>
array(2) {
["text"]=>
string(65) "<div>
<div style="text-align: right;">Im just a text</div>
</div>"
["mce_3"]=>
string(65) "<div>
<div style="text-align: right;">Im just a text</div>
</div>"
}
}
}
}
</pre>
【问题讨论】:
-
而不是在浏览器中看到 - 打开生成的 html。或者在控制台中运行脚本。
-
@u_mulder 没明白你的意思。当编码的json剂量正常工作时,在浏览器中查看数据有什么用。我需要 json,但 json 应该包含带有属性的 html 标签。我已经在浏览器上试过了,数组工作正常,html标签不能直接看到,因为它在浏览器中查看时实现了。
-
在浏览器中查看生成的 json 的源代码。
-
@u_mulder 先生,我已经完成了,我已经在我的问题中粘贴了报价。但这在我的 php 中怎么输出错误。??
标签: php html arrays json multidimensional-array