Reputation: 341
I'm trying to phrase html source using HTML DOM phrase, I need to get a value inside a input tag, I tried this:
foreach ($doc->getElementsByTagName('input') as $link)
{
$links[] = array(
'value' => $link->getAttribute('value'),
'text' => $link->nodeValue,
);
}
This does work for me, but my web page has more that one input tag, but I want to get the value of specified input tag.
Let's say it's,
<input type="hidden" value="11111111" name="tele">
I tried to use getElementsByTagName
, but it gives me an error.
Upvotes: 4
Views: 7739
Reputation: 2632
You can also use the code you have now with a little modification
foreach ($doc->getElementsByTagName('input') as $link)
{
if ($link->getAttribute('name') == 'tele') {
$links[] = array(
'value' => $link->getAttribute('value'),
'text' => $link->nodeValue,
);
}
}
Upvotes: 4
Reputation: 160853
You could use DomXpath
:
$xpath = new DomXpath($doc);
foreach ($xpath->query('//input[@name="tele"]') as $link) {
$links[] = array('value' => $link->getAttribute('value'), 'text' => $link->nodeValue);
}
Upvotes: 2