PHP XML数据解析代码,json,parser函数
程序员文章站
2022-05-10 14:33:31
...
Foo foo@bar.com "; //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, ' Foobar foobar@foo.com
'; } json数据解析代码如下: $json_string='{"id":1,"name":"foo","email":"foo@foobar.com","interest":["wordpress","php"]} '; $obj=json_decode($json_string); echo $obj->name; //prints foo echo $obj->interest[1]; //prints php //xml string $xml_string="Foo foo@bar.com "; //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, ' Foobar foobar@foo.com
'; } ?>
php还自带了一个PHP XML Parser
PHP XML Parser 简介
XML 函数允许我们解析 XML 文档,但无法对其进行验证,XML 是一种用于标准结构化文档交换的数据格式.
下一篇: php 判断来访IP地址是国内还是国外的
推荐阅读
-
php 备份数据库代码(生成word,excel,json,xml,sql)
-
php json_encode()函数返回json数据实例代码
-
PHP使用Http Post请求发送Json对象数据代码解析
-
php 备份数据库代码(生成word,excel,json,xml,sql)_PHP教程
-
php 备份数据库代码(生成word,excel,json,xml,sql)_php技巧
-
everest ultimate edition PHP JSON 数据解析代码
-
persistence.xml PHP XML数据解析代码
-
php 备份数据库代码(生成word,excel,json,xml,sql)
-
php 备份数据库代码(生成word,excel,json,xml,sql)
-
PHP JSON 数据解析代码