我有两个访问库的 PHP 文件(相同的文件夹)simple_html_dom.php
第一个,caridefine.php
有这个:
include('simple_html_dom.php');
$url = 'http://www.statistics.com/index.php?page=glossary&term_id=209';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
libxml_use_internal_errors(true);
$dom = new DomDocument();
$dom->loadHtml($curl_scraped_page);
$xpath = new DomXPath($dom);
print $xpath->evaluate('string(//p[preceding::b]/text())');
第二个,caridefine2.php
有这个:
include('simple_html_dom.php');
$url = 'http://www.statsoft.com//textbook/statistics-glossary/z/?button=0#Z Distribution (Standard Normal)';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scraped_page = curl_exec($ch);
$html = new simple_html_dom();
$html->load($curl_scraped_page);
foreach ($html->find('/p/a [size="4"]') as $font) {
$link = $font->parent();
$paragraph = $link->parent();
$text = str_replace($link->plaintext, '', $paragraph->plaintext);
echo $text;
}
另外,它们每个都运行良好,我运行了caridefine.php
,它运行良好,caridefine2.php
. 但是当我尝试在其他 PHP 文件中加载这两个文件时:
<div class="examples">
<?php
$this->load->view('definer/caridefine.php');
?>
</div>
<div class="examples">
<?php
$this->load->view('definer/caridefine2.php');
?>
</div>
他们都没有工作。只是给了我一个空白页,当我按 时CTRL+U
,它说:Cannot redeclare file_get_html() (previously declared in C:\xampp\htdocs\MSPN\APPLICATION\views\Definer\simple_html_dom.php:70) in C:\xampp\htdocs\MSPN\APPLICATION\views\Definer\simple_html_dom.php on line 85
我搜索了这个问题,我发现“如果你加载许多对象而不清除以前的对象,这可能是个问题。” 我试过做$html->clear()
and unset($dom)
。它什么也没给我。是什么让我喜欢排在最后?
谢谢..