我有一个这样的 html 块:
$localurl = '
<select name="cCountry" id="cCountry" style="width:200" tabindex="5">
<option value="251">Ascension Island</option>
<option selected="selected" value="14">Australia</option>
<option value="13">Austria</option>
';
我正在尝试使用 simple_html_dom (http://simplehtmldom.sourceforge.net/)在这种情况下“澳大利亚”提取选定的值。到目前为止,我已经构建了一个函数但没有工作:
//提取选中的值
函数 getValue_selected($value, $localurl)
{
$html = file_get_html($localurl);
$i = 0;
foreach ($html->find('select[option selected="selected"]') as $k => $v) {
if ($v->name == $value) {
$shows[$i]['Location'] = $v->value;
}
}
$value = $shows[$i]['位置'];
$html->clear();
未设置($html);
返回$值;
}
$selected_value = getValue_selected('cCountry', $localurl)
也可以接受这样的 QueryPath 替代方案。