After the interface is called, $result = can get the following:
StdClass Object
(
[out] = =
T
)
Previously done this directly read XML, but this with a stdClass Object ([out] =
I don't know how to read the contents of each node.
Reply to discussion (solution)
The red code is made by Print_r ($result); catchable fatal error:object of class StdClass could not being converted if it is replaced with Echo $result; To string in
If you are unfamiliar with object manipulation, it can be easier to convert an array first.
The object you get is very simple, $result->out is the XML string, if you want to extract the content, you can try to extract the string, or parse the XML to the object and then to the array (recommended).
http://www.php.net/manual/zh/language.oop5.properties.php
Direct printing
echo $result->out;
Parsing as XML
$xml = simplexml_load_string ($result->out);
Print_r ($xml);
SimpleXMLElement object ([flights] = simplexmlelement object ([flight] = SimpleXMLElement Ob Ject ([@attributes] = = Array ([or Gcity] [SHA] [departterm] = T2 [dstcity]-CAN [Arrivalterm] =--[Aircomp] = MU [flightn O] = MU5307 [Planetype] = [StartTime] = 2012-07-20 0 [EndTime] = 2013-07-20 09:50 [Stopnumber] = 0 [Mealcode] + S) [Cabins] = simplexmlelement Object ([0] = = SimpleXMLElement Object ( [@attributes] = = Array ([Cabin Code] = Y [Cabintype] = 0 [C Abindiscount] [Cabinname] = Economy class [Cabinsales] + A [ibeprice] = 1280 [encryptstring] = 79FCCACUIGJJDSKF) )) [Cabin] = SimpleXMLElement Object ( [@attributes] = = Array ([Cabinco De] + A [Cabintype] = 0 [Cabindiscount] => ; 250 [Cabinname] = First Class discount cabin [cabinsales] = A [Ibeprice] = 2830 [encryptstring] = 1c9cc629e7f7b1a )))) [is_success] [+] = T)
If you are unfamiliar with object manipulation, it can be easier to convert an array first.
The object you get is very simple, $result->out is the XML string, if you want to extract the content, you can try to extract the string, or parse the XML to the object and then to the array (recommended).
PHP code?1http://www.php.net/manual/zh/language.oop5.properties.php
How do I parse XML as an object and then go to an array
Use the DOMDocument method to parse it.
$xml = simplexml_load_string ($result->out);//Convert all properties of an object to an array function Obj2arr ($obj) { $arr = Get_object_vars ($obj) ; foreach ($arr as & $child) { is_object ($child) && ($child = Obj2arr ($child)); } return $arr;} $data = Obj2arr ($xml);
Then you can use
$data [' flights '] [' Flight '] [' cabin '] [' @attributes '] [' cabinname '];
Get first Class discount class
Of course, not converting an array can also be done directly, but this will require testing your basic skills.
PHP code?1234567891011$xml = simplexml_load_string ($result->out);//Convert all properties of an object to an array function
This sentence is displayed with an error:
Simplexml_load_string () [function.simplexml-load-string]: Input conversion failed due to input error
Your PHP is less than 5.3
Only Utf-8 XML is recognized
So the error
Is there any way?
$result->out = str_replace (' encoding= ' GB2312 "', ' encoding= ' Utf-8" ', Iconv (' GBK ', ' utf-8 ', $result->out));
echo $data [' flights '] [' Flight '] [' cabin '] [' @attributes '] [' cabinname '];
Show no data, what's going on