PHP DomDocument output without <?xml version=“1.0” encoding=“UTF-8”?>

后端 未结 4 784
心在旅途
心在旅途 2020-12-10 01:01

is there an option with DomDocument to remove the first line:


The class instantiation auto

4条回答
  •  不知归路
    2020-12-10 01:33

    I think using DOMDocument is a universal solution for valid XML files:

    If you have xml allready loaded in a variable:

    $t_xml = new DOMDocument();
    $t_xml->loadXML($xml_as_string);
    $xml_out = $t_xml->saveXML($t_xml->documentElement);
    

    For XML file from disk:

    $t_xml = new DOMDocument();
    $t_xml->load($file_path_to_xml);
    $xml_out = $t_xml->saveXML($t_xml->documentElement);
    

    This comment helped: http://www.php.net/manual/en/domdocument.savexml.php#88525

提交回复
热议问题