PHP xpath() Function

Description

The xpath() function runs an XPath query on the XML document.

Syntax


  class SimpleXMLElement{
   string xpath(path)
}

Parameter

ParameterIs requiredDescription
pathRequired.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 w  w  w  .java 2  s .c  o m
    <name>PHP</name>
    <name>Java</name>
</book>

PHP Code


<?php// www .j  a  v  a2  s  .  co m
    $xml = simplexml_load_file("test.xml");
    
    $result = $xml->xpath("name");
    
    print_r($result);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions