What if data cannot be read in simpleXMLobject? At the end of this post, joebnb edited class & nbsp; just {function & nbsp; xmlIn simpleXML object from 2014-02-2611: 01: 22. what should I do if the data cannot be read in the object?
This post was last edited by joebnb at 11:01:22
Class just {
Function xmlInclude ($ data ){
$ Xml = simplexml_load_file (dirname (_ FILE _). '/jump. XML ');
Foreach ($ xml-> Keyword-> xpath ("// * [data = '$ data']") as $ item ){
Return $ item;
}
}
}
$ TR = new just;
$ Cr = $ TR-> xmlInclude (query );
Print_r ($ cr );
$ Cr = (array) $ cr;
Echo'
';
Print_r ($ cr );
After writing simplexml parsing, print_r finds that simpleXML object is not an array.
SimpleXMLElement Object ([data] => query [page] => Array ([0] => dbcon. php [1] => select. php [2] => footer. php ))
Array ([data] => query [page] => Array ([0] => dbcon. php [1] => select. php [2] => footer. php ))
How to extract the values, Baidu's answer is to convert them into arrays, and I tried to do the same.
However
echo $cr[0].$cr[0][0].$cr[1][0]
Cannot get the value and prompt:
Notice: Undefined offset: 0 in D: \ Program files \ WEB Edit \ phpLight2013 \ WWW \ Core \ xml. php on line 23
Notice: Undefined offset: 0 in D: \ Program files \ WEB Edit \ phpLight2013 \ WWW \ Core \ xml. php on line 23
How can I directly obtain values from simplexml obj? How can I take an array like this?
------ Solution --------------------
$ Cr = $ TR-> xmlInclude (query );
$ Cr = (array) $ cr;
Echo $ cr ['data'];
Echo $ cr ['Page'] [1];
Note: $ cr = (array) $ cr; converts the first object to an array.