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类和对象相关系统函数与运算符。分享给大家供大家参考,具体如下: 系统函数 class_exists() 判断某个类是否存在...

PHP常用函数小技巧

1. 返回文件扩展名 function getformat($file) { $ext=strrchr($file,"."); $format=strtolower($ext); ret...

php 获取文件后缀名,并判断是否合法的函数

核心代码 /** * 获取文件后缀名,并判断是否合法 * * @param string $file_name * @param array $allow_type * @...

详谈symfony window下的安装 安装时候出现的问题以及解决方法

1. cmd进入DOS  , cd 到 php.exe 的目录下 2. php -r "readfile('http://symfony.com/installer');" &...

PHP 类型转换函数intval

PHP代码 $id = intval($_GET['id']); intval (PHP 4, PHP 5) intval — Get the integer value of a va...