3
我正在使用PHP 5.3。我有以下代碼:PHP DOMDocument getElementsByTagName返回不完整的元素?
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;
}
爲什麼$i->nodeValue
總是給空或者沒有結果?
嘗試在$ i上使用vardump並查看顯示內容。 – miqdadamirali
$ i上的var_dump給了我'對象(DOMElement)#3(0){}' – John
沒關係,我想通了。做一個echo'$ i-> getAttribute('value')'向我展示了我正在尋找的值。 – John