php如何取取xml里的数据

WBOY
Release: 2016-06-13 13:37:55
Original
783 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!