Speed up development with full-stack environments for every branch.

Learn More

Search a certain node [XMLReader, PHP and xml]

1520 Runs 5125 Views 3394 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php

/*
 * PHP XMLReader - Search a certain node
 */

//the tag name of the node we are searching
$what = 'body';

$reader = new XMLReader();
$reader->open('test.xml');
while ($reader->read()) {
    if ($reader->nodeType == XMLReader::ELEMENT) {
        $exp = $reader->expand();
        if ($exp->nodeName == $what)
            echo "<b>" . $exp->nodeName . " : </b>" . $exp->nodeValue . "<br />";
    }
}
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).