0

I have two PHP files (same folders) that access the library simple_html_dom.php

The first one, caridefine.phphas this:

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())');

The second one, caridefine2.php has this:

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;
}

Separately, each of them worked fine, I ran the caridefine.php, it worked well, so did the caridefine2.php. But when I tried to load these two files in other PHP files:

        <div class="examples">
            <?php
                $this->load->view('definer/caridefine.php');
            ?>
        </div>

        <div class="examples">
            <?php
               $this->load->view('definer/caridefine2.php');
            ?>
        </div>

None of them worked. Just gave me a blank page, when I pressed CTRL+U, it said: 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

I googled for this problem, I found that "if you load many objects without clearing the previous ones, it can be a problem." I've tried doing $html->clear() and unset($dom). It gave me nothing. What is it that makes me like in the end of the line?

Thanks..

Fii
  • 39
  • 1
  • 11

1 Answers1

0

I have tried analyse my own problem: Here is the correction:

Change include('simple_html_dom.php'); in each file into: require_once('simple_html_dom.php');

What happened was the file called the file simple_html_dom.php twice. So it won't work. That should do it.

Fii
  • 39
  • 1
  • 11
  • For reference: [What is the difference between PHP require and include?](http://stackoverflow.com/a/3626265/367456) – hakre Jun 25 '13 at 22:10
  • Please accept your answer to mark the question as solved. Also I don't think your question is directly related to the memory leak of that library, so please correct the title so that it's not misleading when searched for. Thank you! – hakre Jun 27 '13 at 02:04
  • Yea, it said to me that I could only accept my answer two days later (which is today), and still have to wait for 11 hours from now. How do I change the title with? – Fii Jun 27 '13 at 04:51
  • A right, there are these periods. I just noted, sometimes users don't see they can do so I leave a note. :) - You can change your questions title by editing the question. – hakre Jun 27 '13 at 06:52
  • No, my question is not how to technically do that, but 'what sentence will best replace the title of this question'? ^^ – Fii Jun 27 '13 at 08:59