A
A
Alexey2017-12-12 11:07:08
Zend Framework
Alexey, 2017-12-12 11:07:08

How to get value in input using Zend\Dom\Query?

I am trying to get the input value in the following code.

<input name="__RequestVerificationToken" type="hidden" value="cOpkqickNLImH72xbqz" />

I do it like this
use Zend\Dom\Query;

$dom = new Query($html); // В $html содержится html-файл, с кодом указанным выше
$results = $dom->execute('input[name="__RequestVerificationToken"]');

$count = count($results); // Значение $count равно 1, значит элемент находится успешно
echo $results->current()->nodeName; // Выводит 'input' - хм... 
echo $results->current()->nodeValue; // Выводит пустое значение. Почему?

// Проверим регулярокой
preg_match('/name="__RequestVerificationToken".+?value="([^"]+)"/', $html, $match);
echo $match[1];// Выводит cOpkqickNLImH72xbqz

How to correctly get the value value in input using Zend\Dom\Query?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2017-12-13
@AlexMaxTM

if($results->count()) {
    $value = $results->current()->getAttribute('value');
}

nodeName - the name of the node, just like in the DOM in the browser
nodeValue - the content of the node, if any. Just like the DOM in the browser
Perhaps you could brush up on your basic knowledge of the DOM before you get into a lot of parsing .

O
oh, 2017-12-13
well @AnneSmith

nodeValue reads exactly the text between tags of the type
and the input tag does not have such text
here, either look for how tag attributes are read in zend, or send the form and read the form values ​​by "name"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question