您现在的位置是:首页 > PHP函数

李清波 2021-06-17 PHP函数 1644 复制当前网址

xpath



PHP xpath() 函数

定义和用法

xpath() 函数运行对 XML 文档的 XPath 查询。

如果成功,则返回包含 SimpleXMLElement 对象的一个数组。如果失败,则返回 false。


语法

class SimpleXMLElement
{
string xpath(path)
}


参数描述
path必需。XPath 路径。


例子

XML 文件:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Dont forget the meeting!</body>
</note>

PHP 代码:

<?php
$xml = simplexml_load_file("test.xml");

$result = $xml->xpath("from");

print_r($result);
?>

输出:

Array
(
[0] => SimpleXMLElement Object
  (
  [0] => John
  )
)



文章来源:https://www.liqingbo.com/blog-797.html

上一篇:addcslashes

下一篇:simplexml_load_string

评论