loadHTML($html);"."/> loadHTML($html);".">
Home >Backend Development >PHP Problem >How to convert html to xml in php
In PHP, you can convert html to xml through "DOMDocument()", with code statements such as "$doc=new DOMDocument();$doc->loadHTML($html);".
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How does php convert html to xml?
About php: Convert HTML source file to XML file
Specific question:
I use this code
$html = file_get_html('http://example.com');
But I want to convert it to XML file and then use some functions on it.
what do I do?
I want to use this code. Can I?
$html = file_get_html('http://example.com'); $doc = new DOMDocument(); $doc->loadHTML($html); $xml=simplexml_load_string($doc) or die("Errooooooor"); print_r($xml);
Solution:
In this case, using DOMDocument() makes it easier to process the HTML.
http://php.net/manual/zh/domdocument.loadhtml.php
$html = file_get_html('http://example.com'); $doc = new DOMDocument(); $doc->loadHTML($html);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert html to xml in php. For more information, please follow other related articles on the PHP Chinese website!