Home  >  Article  >  Backend Development  >  PHP xpath是干什么的

PHP xpath是干什么的

PHPz
PHPzOriginal
2016-06-06 20:43:451416browse

PHP xpath是干什么的

PHP xpath是干什么的?

PHP xpath() 函数

定义和用法

xpath() 函数运行对 XML 文档的 XPath 查询。高佣联盟 www.cgewang.com

如果成功,该函数返回 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&#39;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中文网

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn