How to convert html to xml in php

藏色散人
Release: 2023-03-10 17:22:01
Original
2940 people have browsed it

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');
Copy after login

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);
Copy after login

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);
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template