繁体   English   中英

PHP Simple HTML DOM解析器如何获取非属性元素

[英]PHP Simple HTML DOM Parser how to get non attribute element

TR中的HTML值为:

<input type="radio" name="question_id[1111]" id="question_id[1111]" value="999" class="noborder" checked />Yes</div><div style="white-space:nowrap;margin-right:20px;display:inline-block;">

<input type="radio" name="question_id[1111]" id="question_id[1111]" value="888" class="noborder" />No</div>

我的代码是:

    $html = str_get_html($results);

    foreach($html->find('tr') as $tr)   
    {               
       foreach($tr->find('input') as $input)
       {   
          if ('not sure what to put here' == 'checked')
          {
           print $input->'value';  
          }                                 
       }
    }

我只想确定哪些结果包含“已检查”。 如果是这样,它将返回“值”。 我可以使用$input->'value '获得value的值,但是如何获取非element的值呢?

未经测试,但也许您应该尝试以下方法:

$html = str_get_html($results);

foreach($html->find('tr') as $tr)   
{               
   foreach($tr->find('input[checked]') as $input)
   {   
       print $input->'value';                             
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM