php如何读取xml文件

PHPz
Release: 2020-09-04 15:03:24
Original
2549 people have browsed it

php如何读取xml文件

php读取xml文件的方法:

假设myxml.xml文件中的内容如下

    <resource>
        <res>this is value</res>
        <sound>sound.ogg</sound>
    </resource>
Copy after login

首先我们读取这个xml文件的内容

$xml = file_get_contents(&#39;myxml.xml&#39;);
Copy after login

最重要的一步:解析这个xml文件

$xml_obj = simplexml_load_string($xml);
Copy after login

好了,我们现在有了$xml_obj,我们就可以按照xml文件的结构读取数据了:

//输出 "this is value"
echo $xml_obj->res; 
//输出 "sound.ogg"
echo $xml_obj->sound;
Copy after login

想了解更多编程学习,敬请关注php培训栏目!

Related labels:
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