donglilian0061 2015-12-25 03:11
浏览 109
已采纳

PHP DOMDocument getElementsByTagName返回不完整的元素?

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?

  • 写回答

1条回答 默认 最新

  • doutuoben6908 2015-12-25 03:47
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题