You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.0 KiB
1.0 KiB
title |
---|
Walk::walk |
Walk::walk — Output generator for walking down the DOM tree
Description
public Walk::walk ( \Closure|null $filter = null ) : \Generator
Non-standard. Creates a \Generator
object for walking down the DOM tree. This is in lieu of recreating the awful DOM TreeWalker API.
Examples
Example #1 Print name of every Element
<?php
namespace MensBeam\HTML;
$dom = new Document();
$dom->loadHTML('<!DOCTYPE html><html><head><title>Ook!</title></head><body><h1>Eek</h1></body></html>');
$tree = $dom->walk(function($node) {
return ($node instanceof Element);
});
foreach ($tree as $t) {
echo "{$t->nodeName}\n";
}
?>
The above example will output something similar to:
html
head
title
body
h1