What if data cannot be read in simpleXMLobject? 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?
Reply to discussion (solution)
$ Cr = $ TR-> xmlInclude (query); echo $ cr-> data; echo $ cr-> page [1];
$ Cr = $ TR-> xmlInclude (query); echo $ cr-> data; echo $ cr-> page [1];
Thank you! I also want to know what to do if it is an array? I am a newbie, so I want to understand everything I encounter.
$ 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.
Thank you !~~