将网站转换为 xml? [英] Convert a web site to xml?

查看:76
本文介绍了将网站转换为 xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码获取网站内容:

$data = file_get_contents('http://domain.com/');

现在,我想将 $data 转换为 XML 对象以轻松解析它.例如:

<身体><div id='main'>

</html>

提前致谢

解决方案

有几个类和 API 内置于 PHP 中,随时可以使用.

看看这里:http://www.php.net/手册/en/refs.xml.php

由于您使用网站的源代码,因此最好使用 DOMDocument 并将其加载为 HTML(因为它就是这样).

$data = file_get_contents('http://example.com/');$dom = 新的 DOMDocument();$dom->loadHTML( $data );

I am using this code to get content of a web site:

$data = file_get_contents('http://domain.com/');

And for now, I want to convert $data to an XML object to parse it easily. For example:

<?xml version='1.0' encoding='ISO-8859-1'?>
<html>
    <body>
         <div id='main'>
         </div>
    </body>
</html>

Thank in advance

解决方案

There are several classes and API's built into PHP and ready to use.

Take a look here: http://www.php.net/manual/en/refs.xml.php

Since your using the source of a website, you'd be best using DOMDocument and loading it as HTML (since that's what it is).

$data = file_get_contents('http://example.com/');
$dom = new DOMDocument();
$dom->loadHTML( $data );

这篇关于将网站转换为 xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆