我猜测NameSpaces导致simplexml_load_string
无效,但我肯定不确定。
log.xml
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sns="http://soap.com/pbx">
<env:Body>
<sns:CDR>
<PrimaryCallID>02v7b7c16v@12.123.123.12</PrimaryCallID>
<CallID>d352f920@pbx</CallID>
<From>"SMITH JOHN " <sip:11234567890@sub.domain.com:5060;user=phone></From>
<To><sip:3216549870@111.111.111.111:5060;user=phone></To>
<Direction>O</Direction>
<Type>attendant</Type>
<RemoteParty />
<LocalParty />
<TrunkName />
... more xml...
</sns:CDR>
</env:Body>
</env:Envelope>
parse.php
<?php
$string = "log.xml";
$xml = simplexml_load_string($string);
print_r($xml);
?>
我从print_r
收到任何回复
我错过了什么?
答案 0 :(得分:0)
simplexml_load_string将字符串作为参数而不是文件名 你正试图加载字符串&#34; log.xml&#34;作为XML而且不起作用 你可以使用这个intead:
$filename = "log.xml";
$xml = simplexml_load_string(file_get_contents($filename));
print_r($xml);