The DOMXPath::evaluate() function is an inbuilt function in PHP which is used to execute the given XPath expression which is a pattern defined to select a set of nodes.
mixed DOMXPath::evaluate( string $expression, DOMNode $contextnode, bool $registerNodeNS )
Parameters: This function accept three parameters as mentioned above and described below:
- $expression: It specifies the XPath expression to execute.
- $contextnode (Optional): It specifies the contextnode for doing relative XPath queries. By default, the queries are relative to the root element.
- $registerNodeNS (Optional): It specifies whether to disable automatic registration of the context node.
Return Value: This function returns TRUE on success.
Exceptions: This function throws DOMXPathException on error.
Below examles illustrate the DOMXPath::evaluate() function in PHP:
Number of elements with lang = "en": 2
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.