返回xml作为字符串,但是当我打印它时,所有的开始标记都被忽略PHP


Returning an xml as string, but when I print it, all start tags are ignored PHP

我试图读取一个xml作为一个字符串,我从一个web服务的json得到,当我检查请求的xml看起来很好,但是当我从php打印说json,所有的开始标签被忽略。这种行为有什么原因吗?

{
    "response": "ok",
    "xmlData": "<Tag1><Tag2>data</Tag2><Tag3><Tag4>data</Tag4></Tag3></tag1>"
}
php输出:

{
    "response":"ok",
    "xmlData":"data<'/Tag2>data<'/tag4><'/Tag3><'/tag1>"
}
function webPostRequest($resourceURL, $postContent)
{
    $url = $resourceURL;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postContent);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);
    curl_close($ch);
    echo $result;
    return $result;
}

某些字符在HTML中有特殊的意义,如果要保持它们的含义,就应该用HTML实体来表示。

htmlspecialchars()是你需要修复的