Parsing drop down menu with php simple dom

寵の児 提交于 2019-12-07 10:45:29

Like this :

$dom = new DOMDocument("1.0", "utf-8");
$dom->formatOutput = true;
$dom->loadXML($YOUR_XML_STRING);
$xpath = new DOMXPath($dom);
$res = $xpath->query('//option');
for ($i = 0; $i < $res->length; $i++) {
    $node = $res->item($i);
    $value = $node->getAttribute('value');
    $content = $node->nodeValue;
}

With PHP simple dom :

    $html = str_get_html($YOUR_DROPDOWN_MENU);
    $opt = $html->find('option');
    for ($i = 0; $i < count($opt); $i++) {
        $element = $opt[$i];
        $value = $element->value;
        $content = $element->innertext;
    }

for parsing and getting drop down select values with the help of simple html dom
just try this simple code:

 $element =  $html->find('#selectIDGoesHere',0)->find('option');     
        foreach($element as $elemen) {         
            echo "Display text:".($elemen->plaintext)."<br>"; 
            echo "value:".($elemen->value)."<br>";
        } 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!