How do I create variables from XML data in PHP?

后端 未结 9 1667
不思量自难忘°
不思量自难忘° 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 19:01

    $str = "your xml";
    
    $xml = simplexml_load_string($str);
    $result = array();
    foreach ($xml->positions as $pos) {
        foreach ($pos->position as $p) {
            $element = (string)$p[0];
            $result[$element] = $element;
        }
    }
    
    var_dump($result);
    

提交回复
热议问题