PHP xpath() Function
In this chapter you will learn:
- Description for PHP xpath() Function
- Syntax for PHP xpath() Function
- Parameter for PHP xpath() Function
- Return for PHP xpath() Function
- Example - runs an XPath query on the XML document
Description
The xpath() function runs an XPath query on the XML document.
Syntax
class SimpleXMLElement{
string xpath(path)
}
Parameter
Parameter | Is required | Description |
---|---|---|
path | Required. | What to search for in the XML document |
Return
This function returns an array of SimpleXMLElements on success, and FALSE of failure.
Example
<?xml version="1.0" encoding="ISO-8859-1"?>
<book>//from j av a2 s .com
<name>PHP</name>
<name>Java</name>
</book>
PHP Code
<?php//from j a v a 2 s . co m
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("name");
print_r($result);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP addcslashes() Function
- Syntax for PHP addcslashes() Function
- Parameter for PHP addcslashes() Function
- Return for PHP addcslashes() Function
- Example - Add a backslash in front of the character "W"
- Example - Add backslashes to certain characters in a string
- Example - Add backslashes to a range of characters in a string
Home » PHP Tutorial » PHP SimpleXML Functions