Mik*_*ins 4 html php domdocument
我需要使用PHP <option>从<select>HTML文档中获取所有数据.我目前的代码:
$pageData = $this->Http->get($this->config['url']);
libxml_use_internal_errors(true);
$this->Dom->loadHTML($pageData);
$select = $this->Dom->getElementById('DDteam');
Run Code Online (Sandbox Code Playgroud)
我不确定从这里获取每个选项的值以及选项标签内的文本.我无法使用print_r或类似地检查对象.
您必须使用DOM-API来检索所需的数据.由于<select>元素不是那么复杂,您可以<options>使用getElementsByTagName以下方法获取所有-nodes :
$select = $this->Dom->getElementById('DDteam');
$options = $select->getElementsByTagName('option');
$optionInfo = array();
foreach($options as $option) {
$value = $option->getAttribute('value');
$text = $option->textContent;
$optionInfo[] = array(
'value' => $value,
'text' => $text,
);
}
var_dump($optionInfo);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2291 次 |
| 最近记录: |