How to convert array to SimpleXML

前端 未结 30 2665
遇见更好的自我
遇见更好的自我 2020-11-21 06:52

How can I convert an array to a SimpleXML object in PHP?

30条回答
  •  失恋的感觉
    2020-11-21 07:32

    You could use the XMLParser that I have been working on.

    $xml = XMLParser::encode(array(
        'bla' => 'blub',
        'foo' => 'bar',
        'another_array' => array (
            'stack' => 'overflow',
        )
    ));
    // @$xml instanceof SimpleXMLElement
    echo $xml->asXML();
    

    Would result in:

    
    
        blub
        bar
        
            overflow
        
    
    

提交回复
热议问题