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神奇又有用的Trait

php和java,c++一样都是单继承模式。但是像python,是支持多继承(即Mixin模式)。那么如何在php中实现多继承模式?这就需要使用trait。trait Array...

PHP串行化与反串行化实例分析

PHP串行化与反串行化实例分析

本文实例讲述了PHP串行化与反串行化。分享给大家供大家参考,具体如下: 对象也是一种在内存中存储的数据类型,他的寿命通常随着生成该对象的程序的终止而终止。有时候可能需要把对象的状态保存下...

curl 出现错误的调试方法(必看)

实例如下: private function httpGet($url) { $curl = curl_init(); curl_setopt($curl,...

浅谈PHP中output_buffering

一、我们要说一下php中的缓存大概有哪些! 在PHP中,我们可以粗略的将缓存分为客户端缓存(Browser缓存),服务器端缓存(Server缓存)。由于PHP是基于B/S架构的,所以,我...

php四种定界符详解

闲来无事,研究了与java、c#完全不同的领域php,php即(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”),对于学习php的初学者,不得...