PHP XML数据解析代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

//xml string
$xml_string="<?xml version='1.0'?>
<users>
<user id='398'>
<name>Foo</name>
<email>foo@bar.com</name>
</user>
<user id='867'>
<name>Foobar</name>
<email>foobar@foo.com</name>
</user>
</users>";

//load the xml string using simplexml
$xml = simplexml_load_string($xml_string);

//loop through the each node of user
foreach ($xml->user as $user)
{
//access attribute
echo $user['id'], ' ';
//subnodes are accessed by -> operator
echo $user->name, ' ';
echo $user->email, '<br />';
}

这里是摘自【宜配屋www.yipeiwu.com】之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的PHP函数代码

相关文章

php输出xml格式字符串(用的这个)

复制代码 代码如下: <?php header("Content-type:text/xml;charset=utf-8"); $aaa =<<<html <...

PHP文件系统基本操作类

<?php error_reporting(2047); /* * Class IO (SNakeVil 完成 03.25...

PHP对象转换为数组函数(递归方法)

返回的是一个层次比较分明的数组对象,希望对大家有所帮助,来源WEB开发笔记(www.chhua.com)。 复制代码 代码如下: function object_to_array($ob...

通过PHP CLI实现简单的数据库实时监控调度

要实现的功能:监控user表,若有新纪录增加,将其向user2表中添加。(实际应用上可以引深一些,例如对数据进行相关处理等) 下面是PHP代码(dbtest.php) 复制代码 代码如下...

EarthLiveSharp中cloudinary的CDN图片缓存自动清理python脚本

恰巧发现有个叫“EarthLiveSharp”,可用将日本向日葵8号卫星的地球实时图片设为屏保。向日葵8号卫星的地球实时图片官网为:http://himawari8.nict.go.jp...