Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP DOMDocument getElementsByTagName returns incomplete elements?

I'm using PHP 5.3. I have the following code:

view1.html

<!DOCTYPE html>
<html>
<head>
</head>
<body>
      <form method="post">
         <span>Hello this is some text</span>
         <input type="text" name="input1" value="mystuf"/>
         <p>Blah blah this is boring</p>
         <input type="text" name="input2" value="hello"/>
         <img src="image-of-a-kangaroo.png" />
         <input type="text" name="input3" />
         <ul>
            <li>Buy brocolli</li>
            <li>Buy oregano</li>
            <li>Buy milk</li>
         </ul>
         <input type="text" name="input4" />
         <textarea name="input100"></textarea>
         <input type="text" name="input101" />
         <p><strong>Yes, I like pizza!</strong><span>But my porcupine gets sick eating pizza.</span></p>
      </form>
</body>
</html>

index.php

<?php
$xmlDoc = new DOMDocument();
$xmlDoc->loadHTMLFile('view1.html');
$input = $xmlDoc->getElementsByTagName('input');
foreach ($input as $i) {
        echo $i->nodeValue, PHP_EOL;
}

How come $i->nodeValue always gives empty or no result?

like image 472
John Avatar asked Aug 24 '26 18:08

John


1 Answers

Doing an echo $i->getAttribute('value') showed me the values I was looking for.

like image 63
John Avatar answered Aug 27 '26 09:08

John



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!