I have html file which looks like this:
- item 1
- item 2
- item 3
Passing a DomNode to foreach will not allow you to iterate through its childen, you can easily get the list of li
s and iterate through them.
<?php
$dom = new DOMDocument();
$dom->loadHTML($data);
$postalCodesList = $dom->getElementsByTagName('ul');
foreach ($postalCodesList->item(0)->getElementsByTagName('li') as $postalCodesList) {
echo $postalCodesList->nodeValue.'<br />';
}
?>
DEMO