PHP xpath()函数讲解
发布:smiling 来源: PHP粉丝网 添加日期:2021-11-07 20:00:57 浏览: 评论:0
今天小编就为大家分享一篇关于PHP xpath()函数讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧。
PHP xpath() 函数
定义和用法
xpath()函数运行对 XML 文档的 XPath 查询。
如果成功,该函数返回 SimpleXMLElements 对象的一个数组,如果失败,则返回 FALSE。
语法:
- class SimpleXMLElement
- {
- string xpath(path)
- }
实例
XML 文件
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <note>
- <to>Tove</to>
- <from>Jani</from>
- <heading>Reminder</heading>
- <body>Don't forget me this weekend!</body>
- </note>
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <note>
- <to>Tove</to>
- <from>Jani</from>
- <heading>Reminder</heading>
- <body>Don't forget me this weekend!</body>
- </note>
PHP 代码
- <?php
- $xml = simplexml_load_file("test.xml");
- $result = $xml->xpath("from");
- print_r($result);
- ?>
上面的代码将输出:
- Array
- (
- [0] => SimpleXMLElement Object
- (
- [0] => Jani
- )
- )
Tags: xpath

推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)