我正在尝试使用 HTML DOM 短语来表达 html 源代码,我需要在输入标签中获取一个值,我试过这个:
foreach ($doc->getElementsByTagName('input') as $link)
{
$links[] = array(
'value' => $link->getAttribute('value'),
'text' => $link->nodeValue,
);
}
这对我有用,但我的网页有多个输入标签,但我想获取指定输入标签的值。
假设是,
<input type="hidden" value="11111111" name="tele">
我尝试使用 getElementsByTagName
,但它给了我一个错误。
最佳答案
您也可以使用您现在拥有的代码稍作修改
foreach ($doc->getElementsByTagName('input') as $link)
{
if ($link->getAttribute('name') == 'tele') {
$links[] = array(
'value' => $link->getAttribute('value'),
'text' => $link->nodeValue,
);
}
}
关于php - 按名称获取元素 - HTML DOM 短语,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15927774/