【发布时间】:2011-09-22 23:15:33
【问题描述】:
我有一个这样的 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 替代方案也将被接受。
【问题讨论】:
-
@Gordon 如何使用 QueryPath 获得它?
标签: php html-parsing simple-html-dom simpledom