Home > Backend Development > PHP Tutorial > 求PHP解析XML文件的代码。 100分求。多谢

求PHP解析XML文件的代码。 100分求。多谢

WBOY
Release: 2016-06-13 12:53:04
Original
795 people have browsed it

求PHP解析XML文件的代码。 100分求。谢谢。
1,指定的文件夹下。如:CMMB/02/000601文件夹,查询次文件夹下的的第一个XML文件。

2,xml文件格式如下:

<br />
<?xml version="1.0" encoding="UTF-8"?><br />
<result><br />
<components><br />
<component><br />
<id>common_1</id><br />
<type>common</type><br />
<title>IT时代</title><br />
<items><br />
<item><br />
<id>news/130122001</id><br />
<time>2013-01-21 17:47:02</time><br />
<title><![CDATA[网购影响国人消费习惯 ]]></title><br />
    <description><![CDATA[揭秘“线下试用,线上购买”的“抄码族”]]></description><br />
    <imageNum>1</imageNum><br />
    <isImageOnly>false</isImageOnly><br />
    <content_type>text/html</content_type><br />
    <icon>FA2BD84B53B94CE8B6E35E0F2CB5CBE9.jpg</icon><br />
</item><br />
<item><br />
<id>news/130122002</id><br />
<time>2013-01-21 17:47:02</time><br />
<title><![CDATA[百度遭苹果下架后半日后恢复]]></title><br />
    <description><![CDATA[“除了公关缺失,苹果在中国还需弥补开发者关系这一课。”]]></description><br />
    <imageNum>1</imageNum><br />
    <isImageOnly>false</isImageOnly><br />
    <content_type>text/html</content_type><br />
    <icon>95C96D68E4C6449E860F7C514762D805.jpg</icon><br />
</item><br />
<item><br />
<id>news/130122003</id><br />
<time>2013-01-21 17:47:02</time><br />
<title><![CDATA[2012最爱APP排行榜发布]]></title><br />
    <description><![CDATA[北京晨报制作出一份APP排行榜:我们最爱的十款产品。]]></description><br />
    <imageNum>1</imageNum><br />
    <isImageOnly>false</isImageOnly><br />
    <content_type>text/html</content_type><br />
    <icon>F851463AF50E49DBA1937378BCA1FFD3.jpg</icon><br />
</item><br />
<item><br />
N个item。<br />
</item><br />
</items><br />
</component><br />
</components><br />
</result><br />
Copy after login

3,将XML文件内的数据存入数组。
如:N个item
$arr1[$N]=id
$arr2[$N]=time
$arr3[$N]=title
$arr4[$N]=description
$arr5[$N]=isImageOnly
$arr6[$N]=content_type
$arr7[$N]=icon

4,循环"N"输出数组。
初学PHP不太会,求代码,谢谢。。。

xml
------解决方案--------------------
http://www.cnblogs.com/likwo/archive/2011/08/24/2151793.html看看这个
------解决方案--------------------
simplexml_load_file(filename)
------解决方案--------------------
demo地址:http://sandbox.onlinephpfunctions.com/code/afd0a674a5eaf9ac910d2b3a2b8ec37ff701cec2

$str = 
<?xml  version="1.0" encoding="UTF-8"?><br>
<result><br>
<components><br>
<component><br>
<id>common_1</id><br>
<type>common</type><br>
<title>IT时代</title>
<br>
<items><br>
<item><br>
<id>news/130122001</id><br>
<time>2013-01-21 17:47:02</time><br>
<title></title>
<br>
    <description></description><br>
    <imagenum>1</imagenum><br>
    <isimageonly>false</isimageonly><br>
    <content_type>text/html</content_type> <div class="clear">
                 
              
              
        
            </div></item></items></component></components></result>
Copy after login
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