PHP
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DOMXPath::__construct> <DOMText::splitText
Last updated: Fri, 26 Dec 2008

view this page in

The DOMXPath class

Introducción

Supports XPath 1.0

Class synopsis

DOMXPath
DOMXPath {
/* Properties */
/* Methods */
__construct ( DOMDocument $doc )
mixed DOMXPath::evaluate ( string $expression [, DOMNode $contextnode ] )
DOMNodeList DOMXPath::query ( string $expression [, DOMNode $contextnode ] )
bool DOMXPath::registerNamespace ( string $prefix , string $namespaceURI )
}

Propiedades

document

Prop description

Table of Contents



add a note add a note User Contributed Notes
DOMXPath
Mark Omohundro, ajamyajax dot com
14-Dec-2008 06:15
<?php
// to retrieve selected html data, try these DomXPath examples:

$file = $DOCUMENT_ROOT. "test.html";
$doc = new DOMDocument();
$doc->loadHTMLFile($file);

$xpath = new DOMXpath($doc);

// example 1: for everything with an id
//$elements = $xpath->query("//*[@id]");

// example 2: for node data in a selected id
//$elements = $xpath->query("/html/body/div[@id='yourTagIdHere']");

// example 3: same as above with wildcard
$elements = $xpath->query("*/div[@id='yourTagIdHere']");

if (!
is_null($elements)) {
  foreach (
$elements as $element) {
    echo
"<br/>[". $element->nodeName. "]";

   
$nodes = $element->childNodes;
    foreach (
$nodes as $node) {
      echo
$node->nodeValue. "\n";
    }
  }
}
?>

DOMXPath::__construct> <DOMText::splitText
Last updated: Fri, 26 Dec 2008
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites