loadHTML($html);"."/> loadHTML($html);".">

Home >Backend Development >PHP Problem >How to convert html to xml in php

How to convert html to xml in php

藏色散人
藏色散人Original
2021-06-18 09:11:492972browse

In PHP, you can convert html to xml through "DOMDocument()", with code statements such as "$doc=new DOMDocument();$doc->loadHTML($html);".

How to convert html to xml in php

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn