The xpath() function runs an XPath query on an XML document.
If successful, the function returns an array of SimpleXMLElements objects. If it fails, returns FALSE.
class SimpleXMLElement{string xpath(path)}
parameter | describe |
---|---|
path | Required. Specifies the XPath path to search in the XML document. |
XML file
<?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>
PHP code
<?php$xml = simplexml_load_file("test.xml");$result = $xml->xpath("from");print_r($result);?>
The above code will output:
Array([0] => SimpleXMLElement Object ( [0] => Jani ))