Answer the question
In order to leave comments, you need to log in
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" />
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
Answer the question
In order to leave comments, you need to log in
if($results->count()) {
$value = $results->current()->getAttribute('value');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question