forumphp006:
<?php
$dom2 = new DOMDocument('1.0', 'UTF-8');
$dom2->load('html123.html');
if($dom2->getElementsByTagName('div')[0]->getAttribute('class') === 'class1') {
foreach($dom2->getElementsByTagName('div') as $y) {
foreach($y->childNodes as $x) {
echo $x->getAttribute('class') . PHP_EOL;
}
}
}
?>
html123.html:
<div class="class1"><div class="class2 class3"></div><div class="class4"></div></div>
Rozwiń ten skrypt bardziej według własnych upodobań, podałem bardziej wzór niż rzeczywiste rozwiązanie.
Jeśli zamiast pierwszego znacznika "div" masz "section", to wtedy zamień to:
if($dom2->getElementsByTagName('div')[0]->getAttribute('class') === 'class1') {
foreach($dom2->getElementsByTagName('div') as $y) {
, na to:
if($dom2->getElementsByTagName('section')[0]->getAttribute('class') === 'class1') {
foreach($dom2->getElementsByTagName('section') as $y) {