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函数代码

相关文章

yii框架源码分析之创建controller代码

使用yii框架的url路径一般形如hostname/?r=xxxx/xxxx/xxxx&sdfs=dsfdsf 我们可以看到有时会使用protected目录下的controller,有时...

Array of country list in PHP with Zend Framework

复制代码 代码如下: public static function countryList($local) { $locale = new Zend_Locale('en_US'); $...

php实现分页功能的3种方法第1/3页

直接上代码,希望大家仔细阅读。 方法一:讲sql查询进行分页进行,需要调用几个函数,具体见脚本: 1.pager.class.php <?php class...

PHP函数strip_tags的一个bug浅析

PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。 由于 s...

PHP常用的缓存技术汇总

一、数据缓存 这里所说的数据缓存是指数据库查询缓存,每次访问页面的时候,都会先检测相应的缓存数据是否存在,如果不存在,就连接数据库,得到数据,并把查询结果序列化后保存到文件中,以后同样的...