字符串类型的 XML 变量问题 Php



请查看以下代码

$xml_string = "<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body>
<res:ResultMsg xmlns:res='http://cps.huawei.com/cpsinterface/result'>
<![CDATA[
<?xml version='1.0' encoding='utf-8'?><Result><ResultParameters><ResultParameter><Key>FailedReason</Key><Value>The value 611015125123 of the CNIC parameter is incorrect, failed to authenticate the parameter.</Value></ResultParameter></ResultParameters><ResultCode>2002</ResultCode><ResultType>0</ResultType><OriginatorConversationID>20180904165750</OriginatorConversationID><ResultDesc>Transaction information is invalid.</ResultDesc><TransactionID>000000000000</TransactionID><ConversationID>AG_20180904_00007be9004e56992e5f</ConversationID></Result>]]>
</res:ResultMsg>
</soapenv:Body>
</soapenv:Envelope>";

然后我得到变量的类型

$type=gettype($xml_string);

回声弦好了。 当我尝试回显实际值时,它只是打印出其中的一部分。

FailedReasonThe value 611015125123 of the CNIC parameter is incorrect, failed to authenticate the parameter.2002020180904165750Transaction information is invalid.000000000000AG_20180904_00007be9004e56992e5f]]>

为什么会发生这种奇怪的行为。我也尝试替换所有新的行字符,但没有帮助。任何提示都值得赞赏。

我最后的愚蠢错误,如果有人偶然发现这个问题,请回答。根据对我问题的评论,我有完整的数据,但由于标签的原因,浏览器没有显示它。

echo "<textarea>";
echo $manual ;     
echo "</textarea>";

做了这项工作。

$regex = '#<Value>(.*?)</Value>#';
$code = preg_match($regex, $xml_string, $matches);
echo $matches[0];

你可以试试这种方式。它不是一个xml解析,它更像是一个php/regex方法,但会为你完成工作。

输出为:CNIC参数的值611015125123不正确,参数认证失败。

我也遇到了与您解析此 soap-xml 响应相同的问题,因此我想到了这个有效的解决方法。毕竟它是一个字符串类型,php 有非常好的工具来解析使用正则表达式的字符串。

最新更新