2
Good afternoon guys! I am doing this way to get the value of each input that is within the $html variable
I have tried other methods to decrease that much of foreach for each input, more unsuccessfully.
as I do to use only a foreach or something of the type, to search all inputs, take the values and put each one in a variable .
I’m doing like this.
$html = '
<html>
<body>
<input name="nome" id="nome" value="carlos" type="hidden">
<input name="sobrenome" id="sobrenome" value="silva" type="hidden">
<input name="nascimento" id="nascimento" value="1992" type="hidden">
</body>
</html>
';
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
foreach ($xpath->query("*/input[@name='nome']") as $p) {
$nome = $p->getAttribute('value');
}
foreach ($xpath->query("*/input[@name='sobrenome']") as $p) {
$sobre= $p->getAttribute('value');
}
foreach ($xpath->query("*/input[@name='nascimento']") as $p) {
$nasc= $p->getAttribute('value');
}
## RESULTADOS
echo '<b style="color:red;">NOME:</b> <br />' . $nome;
echo '<br /><b style="color:red;">SOBRENOME:</b> <br />' . $sobre;
echo '<br /><b style="color:red;">DATA DE NASCIMENTO:</b> <br />' . $nasc;
What kind of input is this? form?
– gabrielfalieri
that is the input of a common form, and pq the site did not send code :/ ex: '< input name="name" id="name" type="text">' .. < input name="last name" id="last name" type="text"> .. < input name="birth" id="birth" type="text">
– carlos1992