Php 获取全部<;选项>;来自<;选择>;使用getElementById
我需要使用PHP从HTML文档中的Php 获取全部<;选项>;来自<;选择>;使用getElementById,php,html,domdocument,Php,Html,Domdocument,我需要使用PHP从HTML文档中的获取所有数据。我目前拥有的代码: $pageData = $this->Http->get($this->config['url']); libxml_use_internal_errors(true); $this->Dom->loadHTML($pageData); $select = $this->Dom->getElementById('DDteam'); 我不知道如何从这里获得每个选项的值以及选项标记中的文本
获取所有
数据。我目前拥有的代码:
$pageData = $this->Http->get($this->config['url']);
libxml_use_internal_errors(true);
$this->Dom->loadHTML($pageData);
$select = $this->Dom->getElementById('DDteam');
我不知道如何从这里获得每个选项的值以及选项标记中的文本。我无法使用
print\r
或类似工具检查对象 您必须使用DOM-API来检索所需的数据。由于
元素没有那么复杂,您可以使用以下方法获取所有
-节点:
$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);