Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过wp\u insert\u post将有效的JSON保存到带斜杠的wordpress post内容(转义html)_Php_Mysql_Json_Wordpress - Fatal编程技术网

Php 通过wp\u insert\u post将有效的JSON保存到带斜杠的wordpress post内容(转义html)

Php 通过wp\u insert\u post将有效的JSON保存到带斜杠的wordpress post内容(转义html),php,mysql,json,wordpress,Php,Mysql,Json,Wordpress,我有一个JSON字符串,它用斜杠将html正确地分条 { "sections": [ { "section_name": "Objective", "data": "<span style=\"font-weight: bold;\">Test</span>", "key": "ref" } ] } { “章节”:[ { “部门名称”:“目标”, “数据”:“测试”, “键”:“参考” } ] } 现在我正试

我有一个JSON字符串,它用斜杠将html正确地分条

{
  "sections": [
    {
      "section_name": "Objective",
      "data": "<span style=\"font-weight: bold;\">Test</span>",
      "key": "ref"
    }
  ]
}
{
“章节”:[
{
“部门名称”:“目标”,
“数据”:“测试”,
“键”:“参考”
}
]
}
现在我正试图通过wp_insert_post将这个json字符串插入worpdres post内容

$data = '{"sections":[{"section_name":"Objective","data":"<span style=\"font-weight: bold;\">Test</span>","key":"ref"}]}';
    $new = array(
                'post_title'    => $title,
                'post_content'  => $data,
                'post_author'    => $userid,
                'post_status'   => 'pending',
                'post_type' => 'post'
              );
         $id = wp_insert_post($new );
$data='{“sections”:[{“section_name”:“Objective”,“data”:“Test”,“key”:“ref”}]}';
$new=数组(
“post_title”=>$title,
“post_内容”=>$data,
“post_author”=>$userid,
“post_状态”=>“挂起”,
“职位类型”=>“职位”
);
$id=wp\u insert\u post($new);
现在在插入的帖子中,我看到斜杠被自动删除

所以当我得到帖子内容时,它就变成了无效的JSON

但是,我可以通过wordpress admin直接保存有效的JSON,或者通过phpmyadmin保存到mysql数据库。它按预期工作

如何将有效的JSON保存到带有斜杠(转义html)的wordpress帖子内容, “post_内容”=>$data, “post_author”=>$userid, “post_状态”=>“挂起”, “职位类型”=>“职位” ); $id=wp\u insert\u post($new); 这起作用了

data = <<<EOD
{"sections":[{"section_name":"Objective","data":"<span style=\"font-weight: bold;\">Test</span>","key":"ref"}]}
EOD;
    $new = array(
                'post_title'    => $title,
                'post_content'  => $data,
                'post_author'    => $userid,
                'post_status'   => 'pending',
                'post_type' => 'post'
              );
         $id = wp_insert_post($new );