PHP xpath() 函数
PHP 教程
· 2019-01-29 09:28:49
定义和用法
xpath() 函数运行对 XML 文档的 XPath 查询。
如果成功,该函数返回 SimpleXMLElements 对象的一个数组。如果失败,则返回 FALSE。
语法
class SimpleXMLElement
{
string xpath(path)
}
| 参数 | 描述 |
|---|---|
| path | 必需。规定要在 XML 文档中搜索的 XPath 路径。 |
实例
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>
PHP 代码
<?php
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("from");
print_r($result);
?>
上面的代码将输出:
Array ( [0] => SimpleXMLElement Object ( [0] => Jani ) )
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Algorithms
Robert Sedgewick、Kevin Wayne / Addison-Wesley Professional / 2011-3-19 / USD 89.99
Essential Information about Algorithms and Data Structures A Classic Reference The latest version of Sedgewick,s best-selling series, reflecting an indispensable body of knowledge developed over the ......一起来看看 《Algorithms》 这本书的介绍吧!