Here is a basic example of how simple_html_dom works in a standalone php file.
test.php:
include ('simple_html_dom.php');
$url = "http://www.google.com";
$html = new simple_html_dom();
$html->load_file($url);
print $html;
If I execute it with the command: php test.php
It dumps correctly the html of the website (in this example, google.com)
Now let’s take a look at a basic example of code using a Symfony task:
class parserBasic extends sfBaseTask {
public function configure()
{
$this->namespace = 'parser';
$this->name = 'basic';
}
public function execute($arguments = array(), $options = array())
{
$url = "http://www.google.com";
$html = new simple_html_dom();
$html->load_file($url);
print $html;
}
}
This file it’s located under: <appname>/lib/task
I don’t need to include the library in the file because being under the lib/task folder, it gets automatically loaded.
I execute the task using this command: php symfony parser:basic
And I get the following error message:
PHP Fatal error:
Call to a member function innertext() on a non-object in
/home/<username>/<appname>/lib/task/simple_html_dom.php on line 1688
Any suggestions?
The problem comes from Symfony.
In fact, if an error occur when loading the file with
simple_html_dom, it won’t say anything but returning false.For example, if you perform this in your task:
You will get an exception. If you tweak
simple_html_domto display en error when loading a file, around line 1085:You will see:
I usually got this error (which is, in fact, a notice) when using task. The problem is here, in
sfCommandApplication, withob_end_flush:To fix that, I comment the line with
@ob_end_flush();. And every thing goes fine. I know, it’s an ugly fix, but it works. An other way to fix that, is to disable notice from PHP (inphp.ini), like :