Home  >  Article  >  Backend Development  >  php如何取取xml里的数据

php如何取取xml里的数据

WBOY
WBOYOriginal
2016-06-13 13:37:55785browse

php怎么取取xml里的数据?

 php如何取取xml里的数据

http://www.china-lz.org/
http://www.china-lz.org/
http://www.china-lz.org/
http://www.china-lz.org/


6



我想取http://www.china-lz.org/里面path,smallinfo,url
放到数组里,我用$xml = simplexml_load_file('file.xml'),foreach $xml->pic 取不出来。

------解决方案--------------------
DOM解法:

PHP code

$doc = new DomDocument();
$doc->load("file.xml"); 
$lists=$doc->getElementsByTagName("list");
foreach($lists as $list){
      $path=$list->getAttribute("path"); 
      $smallinfo=$list->getAttribute("smallinfo"); 
     $arr[]=array('path'=>$path,'smallinfo'=>$smallinfo,'url'=>$list->nodeValue);
}
print_r($arr); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn