How to traverse XML files-php Tutorial

Source: Internet
Author: User
How can I traverse XML files? how can I traverse xml files and put them into the database?




Fruit
Tree
Flower
Others


Lu
Sea
Others



I want to traverse the frontend results in this way.


Reply to discussion (solution)

Organize your own display.

$ S = <
 
    
   
      
     Fruit  
     Tree  
     Flower  
     Others
       
      
     Lu  
     Sea  
     Others
      
   
  EOF; $ x = simplexml_load_string ($ s); $ data = []; foreach ($ x-> Evaluations as $ Evaluations) {foreach ($ Evaluations-> Evaluation as $ Evaluation) {$ tmpData = current ($ Evaluation-> attributes ()-> data); if (! Isset ($ data ["$ tmpData"]) {$ data ["$ tmpData"] = [];} foreach ($ Evaluation-> OBJECT as $ OBJECT) {$ data ["$ tmpData"] ["$ OBJECT"] = current ($ OBJECT-> attributes ()-> data) ;}} print_r ($ data ); /* Array ([plant system] => Array ([fruit] => apple, pear [tree] => bamboo, rich bamboo [Flower] => Chrysanthemum, carnation [others] =>) [animal system] => Array ([land] => Tiger, Lion [Sea] => fish, Seahorse [others] => ))*/
 

Organize your own display.

$ S = <
 
    
   
      
     Fruit  
     Tree  
     Flower  
     Others
       
      
     Lu  
     Sea  
     Others
      
   
  EOF; $ x = simplexml_load_string ($ s); $ data = []; foreach ($ x-> Evaluations as $ Evaluations) {foreach ($ Evaluations-> Evaluation as $ Evaluation) {$ tmpData = current ($ Evaluation-> attributes ()-> data); if (! Isset ($ data ["$ tmpData"]) {$ data ["$ tmpData"] = [];} foreach ($ Evaluation-> OBJECT as $ OBJECT) {$ data ["$ tmpData"] ["$ OBJECT"] = current ($ OBJECT-> attributes ()-> data) ;}} print_r ($ data ); /* Array ([plant system] => Array ([fruit] => apple, pear [tree] => bamboo, rich bamboo [Flower] => Chrysanthemum, carnation [others] =>) [animal system] => Array ([land] => Tiger, Lion [Sea] => fish, Seahorse [others] => ))*/
 


Why can't I find the page?

The webpage cannot be found... it's your server error, or the link is wrong...

The webpage cannot be found... it's your server error, or the link is wrong...


I changed [] to array (). how can I output the output array to the front-end of thinkphp? How to nest volist output

[] Php 5.4 +

Distribute to foreground
$ This-> assign ('data', $ data );


How do I display them cyclically? what style should I add? it's your business.
Http://document.thinkphp1.cn/manual_3_2.html#volist

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.