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.1 KiB
1.1 KiB
title |
---|
Moonwalk::moonwalk |
Moonwalk::moonwalk — Output generator for walking up the DOM tree
Description
public Moonwalk::moonwalk ( \Closure|null $filter = null ) : \Generator
Non-standard. Creates a \Generator
object for walking up the DOM tree. This is in lieu of recreating the awful DOM TreeWalker API.
Examples
Example #1 Print name of all ancestors of the H1 element
<?php
namespace MensBeam\HTML;
$dom = new Document();
$dom->loadHTML('<!DOCTYPE html><html><head><title>Ook!</title></head><body><h1>Eek</h1></body></html>');
$h1 = $dom->getElementsByTagName('h1')->item(0);
// All ancestors will be elements so there's no reason to have a filter.
$tree = $h1->moonwalk();
foreach ($tree as $t) {
echo "{$t->nodeName}\n";
}
?>
The above example will output something similar to:
body
html