php 读取 xml 文件

2025-11-02 04:53:39

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

    <resource>

        <res>this is value</res>

        <sound>sound.ogg</sound>

    </resource>

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

$xml = file_get_contents('myxml.xml');

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

$xml_obj = simplexml_load_string($xml);

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

//输出 "this is value"

echo $xml_obj->res; 

//输出 "sound.ogg"

echo $xml_obj->sound; 

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢