Current scenario :
I'm loading a html page into a var with DomDocument
$dom = new DOMDocument('1.0', 'UTF-8');
@$dom->loadHTML($html);
and I need to parse 3 lists of option fields . The HTML looks like this :
<li>
<select id="advertiser" name="advertiser[]" multiple="multiple" autocomplete="off"> <option value="35" >Website Adv 1</option>
<option value="36" >Website Adv 1</option> <option value="41" >Website Adv 1</option>
<option value="45" >Website Adv 1</option>
</select>
</li>
Now I found this code on Stack but it does not work ..
$xpath = new DOMXpath($dom);
$options = $xpath->query("*/select[@name='advertiser[]']/option");
foreach ($options as $option) {
$optionValue = $option->getAttribute('value');
$optionContent = $option->nodeValue;
echo "$optionValue and $optionContent\n";
}
The question remains :
How do I parse a HTML page to extract the fields of an option select, into an array like : value=>option_text
//select[@name...instead of*/select