PHP XML数据解析代码

yipeiwu_com5年前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文件锁定写入实例解析

本文以实例讲述了PHP文件写入方法,以应对多线程写入,具体代码如下: function file_write($file_name, $text, $mode='a', $timeo...

ThinkPHP中调用PHPExcel的实现代码

核心代码: //引入PHPExcel vendor('PHPExcel.PHPExcel'); // Create new PHPExcel object $objPHPExcel...

PHP的拦截器实例分析

本文实例讲述了PHP的拦截器用法。分享给大家供大家参考。具体如下: PHP提供了几个拦截器,用于在访问未定义的方法和属性时被调用,如下所示: 1、__get($property) 功能:...

什么是PHP文件?如何打开PHP文件?

什么是PHP文件?如何打开PHP文件?

在平时我们可能会碰到过php文件,可是很多用户不知道php文件是什么文件?也不知道怎么打开php文件?为了满足一些用户的好奇心,小编现在就给大家讲解php文件以及如何打开...

用PHP获取Google AJAX Search API 数据的代码

http://code.google.com/apis/ajaxsearch/documentation/ 复制代码 代码如下: // This example request incl...