gpt4 book ai didi

php - JSON 对象与 html 实体崩溃

转载 作者:行者123 更新时间:2023-11-30 00:22:03 25 4
gpt4 key购买 nike

我有以下 PHP 脚本,它从 MySQL 表创建一个 JSON 对象。

$arr = array();

$rs = mysql_query("SELECT post_title, post_content, meta_value FROM wp_posts LEFT JOIN wp_postmeta ON ID = post_id and meta_key = '_wp_attached_file' ");

while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo '{"members":'.json_encode($arr).'}';

我的表中的一列称为 post_content,其中包含 url 链接等 html 实体。正是这个导致了程序崩溃。

如何解决这个问题?

崩溃enter image description here

最佳答案

检查http://php.net/json_encode ,您必须添加第二个参数才能使其正确转义..

JSON_HEX_TAG
All < and > are converted to \u003C and \u003E. Available since PHP 5.3.0.

检查http://www.php.net/manual/en/json.constants.php

关于php - JSON 对象与 html 实体崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23156287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com