Last active
September 9, 2020 06:51
Revisions
-
ik5 revised this gist
Sep 9, 2020 . 1 changed file with 19 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,24 +11,28 @@ for ($i =0; $i < $nodes->length; $i++) { $item = $nodes->item( $i ); if ($item->childNodes->length <= 0) { continue; } for ($j = 0; $j < $item->childNodes->length; $j++) { $childItem = $item->childNodes->item($j); echo $childItem->nodeName; echo ' = '; echo $childItem->nodeValue; if (!$childItem->hasAttributes()) { continue; } for ($a = 0; $a < $childItem->attributes->length; $a++) { $attr = $childItem->attributes->item($a); echo "\t"; echo $attr->nodeName; echo ' = '; echo $attr->nodeValue; echo "\n"; } echo "\n"; } } -
ik5 created this gist
Sep 8, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ <?php $doc = new DOMDocument(); $doc->loadHTMLFile('test.html', LIBXML_NOWARNING | LIBXML_NOERROR); $nodes = $doc->getElementsByTagName('head'); if ($nodes->length <= 0) { die('no head found'); } for ($i =0; $i < $nodes->length; $i++) { $item = $nodes->item( $i ); if ($item->childNodes->length > 0) { for ($j = 0; $j < $item->childNodes->length; $j++) { $childItem = $item->childNodes->item($j); echo $childItem->nodeName; echo ' = '; echo $childItem->nodeValue; if ($childItem->hasAttributes()) { for ($a = 0; $a < $childItem->attributes->length; $a++) { $attr = $childItem->attributes->item($a); echo "\t"; echo $attr->nodeName; echo ' = '; echo $attr->nodeValue; echo "\n"; } } echo "\n"; } } } ?>