0

我正在尝试打印来自 xml 结果的响应。

<?xml version="1.0"?>
<response op="sendsmsmsg" status="400" message="Customer with mobile number 6193030168 is not opted in" version="1.0"/>
SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [op] => sendsmsmsg
            [status] => 400
            [message] => Customer with mobile number 6193030168 is not opted in
            [version] => 1.0
        )

)

如何将此结果的操作值,状态,消息回显到php中

4

2 回答 2

0

似乎 XML 格式错误。这个有效。经过测试

<?php
$string = <<<XML
<?xml version='1.0' standalone='yes'?>
<response2>
 <op>sendsmsmsg</op>
  <status>400</status>
   <message>Customer with mobile number 6193030168 is not opted in</message>
</response2>
XML;

$xml = new SimpleXMLElement($string);
echo $xml->op."<br>".$xml->status."<br>".$xml->message;
?>

输出

sendmsmsg
400
手机号码为 6193030168 的客户未选择加入

于 2013-08-15T11:58:19.900 回答
0

我已经用你的 xml 对其进行了测试:

//data.xml has 
<?xml version="1.0"?>
<response op="sendsmsmsg" status="400" message="Customer with mobile number 6193030168 is not opted in" version="1.0"/>


<?php
$xml = simplexml_load_file('data.xml');
print($xml['op']);
?>
于 2013-08-15T13:01:04.023 回答