以字符串形式返回xml,但是当我打印它时,所有开始标签都将被忽略PHP [英] Returning an xml as string, but when I print it, all start tags are ignored PHP

查看:223
本文介绍了以字符串形式返回xml,但是当我打印它时,所有开始标签都将被忽略PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im来读取xml,当我检查请求时xml看起来不错,但是当我从php打印出json时,所有开始标签都将被忽略.有这种行为的原因吗?

im trying to read an xml as a string that i get from a json from a webservice, when I check the request the xml looks fine, but when I print said json from php, all the start tags are ignored. Is there a reason for this behavior?

{
    "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实体表示.

Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings.

htmlspecialchars()是您需要解决的问题

htmlspecialchars() is what you need to fix this

这篇关于以字符串形式返回xml,但是当我打印它时,所有开始标签都将被忽略PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆