PHP xpath() 函數
PHP xpath() 函數

定義和用法
xpath() 函數運行對 XML 文檔的 XPath 查詢。
如果成功,該函數返回 SimpleXMLElements 對象的一個數組。如果失敗,則返回 FALSE。
語法
class SimpleXMLElement
{
string xpath(path)
}
{
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>
<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);
?>
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("from");
print_r($result);
?>
上面的代碼將輸出:
Array
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)

相關文章
- PHP 運算符
- PHP Cookie
- PHP 過濾器
- PHP array_diff() 函數
- PHP array_fill_keys() 函數
- PHP array_intersect_uassoc() 函數
- PHP array_reduce() 函數
- PHP array_reverse() 函數
- PHP array_search() 函數
- PHP array_udiff_uassoc() 函數
- PHP array_uintersect() 函數
- PHP array_unshift() 函數
- PHP compact() 函數
- PHP key() 函數
- PHP natsort() 函數
- PHP sort() 函數
- PHP uasort() 函數
- PHP Libxml 函數
- PHP Mail 函數
- PHP 5 MySQLi 函數