Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best PHP parser for invalid format xml [duplicate]

Whats the best xml parser to use especially for XML that's technically invalid format with the <?xml tag missing?

I cant use simpleXML because that gives a error for being invalid. I know i can manually add the tags I need after i get the xml but id prefer to see what you guys think is the best method for parsing a xml into an array in php.

like image 744
Yeak Avatar asked Sep 27 '26 00:09

Yeak


1 Answers

You can use SimpleXML and disable errors by using libxml_use_internal_errors(false);. In case SimpleXML simply won't use your string, I've personally used DOM to parse/fix broken XML before.

On the other hand, why don't you simply add the <?xml characters before reading it?

like image 191
h2ooooooo Avatar answered Sep 29 '26 13:09

h2ooooooo