php,simple_html_dom.php,获取选择的选项 [英] php , simple_html_dom.php, get selected option

查看:111
本文介绍了php,simple_html_dom.php,获取选择的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似这样的html块:

I have a html block like this :


$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/).到目前为止,我已经构建了一个函数,但是无法正常工作:

I'm trying to extract the selected value in this case "Australia" using simple_html_dom ( http://simplehtmldom.sourceforge.net/ ). So far I have build a function but is not working :

//提取所选值


function 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]['Location'];
$html->clear();
unset($html);
return $value;
}

  $selected_value = getValue_selected('cCountry', $localurl)

也可以接受诸如QueryPath这样的替代方法.

An alternative such QueryPath would be accepted too .

推荐答案

正确的答案是:

$html->find('#cCountry',0)->find('option[selected=selected]',0);

这篇关于php,simple_html_dom.php,获取选择的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆