处理;PHP HTML DOM解析器“;,将同一个库包含到两个不同的文件中

处理;PHP HTML DOM解析器“;,将同一个库包含到两个不同的文件中,php,dom,syntax,html-parsing,Php,Dom,Syntax,Html Parsing,我有两个PHP文件(相同的文件夹)可以访问库simple\u html\u 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);

我有两个PHP文件(相同的文件夹)可以访问库
simple\u html\u 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())');
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;
}
第二个,
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
时,它说:
无法重新声明C:\xampp\htdocs\MSPN\APPLICATION\views\Definer\simple\U html\U dom.php第85行的C:\xampp\htdocs\MSPN\APPLICATION\views\Definer\simple\U html\U dom.php中声明的文件()

我在谷歌上搜索这个问题,我发现“如果你加载了很多对象而没有清除之前的对象,这可能是个问题。” 我试过做
$html->clear()
unset($dom)
。它什么也没给我。 到底是什么让我喜欢排在最后


谢谢..

我试着分析我自己的问题: 更正如下:

更改
include('simple_html_dom.php')编码为:
require_once('simple_html_dom.php')

发生了两次称为file
simple\u html\u dom.php的文件。所以它不会起作用。

应该可以了。

参考:请接受您的答案,将问题标记为已解决。此外,我认为你的问题与该库的内存泄漏没有直接关系,因此请更正标题,以便在搜索时不会产生误导。非常感谢。是的,它告诉我,我只能在两天后(也就是今天)接受我的答案,而且从现在起还要等11个小时。我该如何更改标题?A对,有这些句点。我只是注意到,有时用户看不到他们可以这样做,所以我留了一张便条。:)你可以通过编辑问题来更改你的问题标题。不,我的问题不是如何从技术上做到这一点,而是“哪句话最能取代这个问题的标题”^^