How do I create variables from XML data in PHP?

后端 未结 9 1704
不思量自难忘°
不思量自难忘° 2021-01-25 18:34

Been trying to figure this out for a short while now but having now luck, for example I have an external xml document like this:


&         


        
9条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-25 18:57

    Take a look at SimpleXML:

    http://www.php.net/manual/en/simplexml.examples-basic.php
    

    It parses XML into a "map-like" structure which you could then use to access your content. For your particular case,

    $xml = new SimpleXMLElement($xmlstr);
    
    $top_a =  $xml->template->positions[0] 
    

提交回复
热议问题