我是php的新手。此外,我在这里讨论了很多主题。
可能会有轻微的故障,但我无法阅读。
//parse xml string into SimpleXML objects
$returnxml = simplexml_load_string($result);
if ($returnxml === false) {
die('Error parsing Return XML');
}
//now we can loop through the xml structure
foreach ($returnxml->channel->item as $item) {
print $item->title;
}
<?xml version="1.0" encoding="ISO-8859-1"?>
<ncresponse
orderID="120130414021640"
PAYID="BESALDOM 516A65F5E5E"
STATUS="4"
NCSTATUS="0"
NCERROR=""
NCERRORPLUS="Your transaction has been submitted for processing."
ACCEPTANCE="BINF-"
IPCTY=""
CCCTY=""
IDUsager="7884TSMA"
/>
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $this->omnipayment_action_url);
curl_setopt($ch,CURLOPT_POST, count($myorder));
curl_setopt($ch,CURLOPT_POSTFIELDS, $flds);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close($ch);
在此先感谢,任何帮助将不胜感激...
答案 0 :(得分:1)
正确地Adidi pointed out,您并未尝试从正确的位置获取提供给您的信息。您需要的信息位于根节点中并存储为attributes,这是一个快速示例,说明如何获取这些信息: -
<?php
function parse_response($response) {
$xml = new SimpleXMLElement($response);
$arr = array();
foreach($xml->attributes() as $key => $value) {
$arr[(string)$key] = (string)$value;
}
return $arr;
}
var_dump(parse_response($str));
/*
array(10) {
["orderID"]=>
string(15) "120130414021640"
["PAYID"]=>
string(20) "BESALDOM 516A65F5E5E"
["STATUS"]=>
string(1) "4"
["NCSTATUS"]=>
string(1) "0"
["NCERROR"]=>
string(0) ""
["NCERRORPLUS"]=>
string(51) "Your transaction has been submitted for processing."
["ACCEPTANCE"]=>
string(5) "BINF-"
["IPCTY"]=>
string(0) ""
["CCCTY"]=>
string(0) ""
["IDUsager"]=>
string(8) "7884TSMA"
}
*/
答案 1 :(得分:0)
简单加载xml文件..
<?php
$xml = @simplexml_load_string($result);
$status = (string)$xml->Status;
$operator_trans_id = (string)$xml->OPID;
$trns_id = (string)$xml->TID;