【发布时间】:2012-11-30 15:49:48
【问题描述】:
这段代码有以下错误,我希望它从 HTML 中抓取一个选定的对象,而不是整个文件。
php 文件:
<?php
include_once('simple_html_dom.php');
$target = "test.html";
$html = file_get_contents($target);
foreach($html->find('div.article') as $element)
echo $element->find('h1');
?>
test.html:
<html>
<head>
</head>
<body>
<div class="article">
<h1>Header</h1>
<p>Paragraph</p>
</div>
</body>
</html>
输出:
Fatal error: Call to a member function find() on a non-object in C:\xampp\htdocs\index.php on line 7
【问题讨论】: