我有一个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 );
现在在插入的帖子中,我看到斜杠被自动删除了。
所以当我得到的帖子内容,它变成无效的JSON。
但是我可以直接通过wordpress admin保存有效的JSON,或者通过phpmyadmin保存到mysql数据库。它像预期的那样工作。
如何用斜杠(转义的html)保存有效的JSON到wordpress post内容
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 );
这工作。