PHP xpath是干什么的

PHPz
Release: 2020-09-04 15:30:49
Original
1426 people have browsed it

PHP xpath是干什么的

PHP xpath是干什么的?

PHP xpath() 函数

定义和用法

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

如果成功,该函数返回 SimpleXMLElements 对象的一个数组。如果失败,则返回 FALSE。

语法

class SimpleXMLElement
{
string xpath(path)
}
Copy after login

参数

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>
Copy after login

PHP 代码

<?php
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("from");
print_r($result);
?>
Copy after login

上面的代码将输出:

Array
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
Copy after login

更多相关技术文章,请访问PHP中文网

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!