Jump to content

Problem loading a file into simplehtmldom


eatc7402

Recommended Posts

I am a new simplehtmldom user. It is working and the php api loads, and I can parse

when I lod data from a string. But if I attemp yo load data from a file like this...

$html->file_get_html("C:\eaahmpg\eatc7402\www\stations\Sydney\code\table_data.txt");

 

I receive the following error.

Fatal error: Call to undefined method simple_html_dom::file_get_html() in...

 

Hmmm. The function IS defined in the api.

 

I'm not sure where I'M going wrong here.

 

eac7402

I've never used it before, but from what I found on Google it looks like file_get_html() is just a standalone function that returns the object. I.e. you call it like:

 

$html = file_get_html("C:\eaahmpg\eatc7402\www\stations\Sydney\code\table_data.txt");

Ahhh yes.. an EQUAL sign... that fixed that error.. but NOW I  get this...

 

Warning: file_get_contents(C:\eaahmpg\eatc7402\www\stations\Sydney\code able_data.txt) [function.file-get-contents]: failed to open stream: Invalid argument in C:\eaahmpg\eatc7402\www\php\simplehtmldom\simple_html_dom.php on line 39

 

An argument? What does it need here.. if I give it an empty argument is complains also.

 

$html = file_get_html("C:\eaahmpg\eatc7402\www\stations\Sydney\code\table_data.txt", "");

 

eatc7402

 

I altered my code and when I called the function WITHOUT a file path like this...

 

$html = file_get_html("table_data.txt");

 

it no longer complains about any missing arg.

 

So... what is the required arg if I want to  fully specify the path to the file??

 

eatc7402

"\t" in PHP is the special tab-character. As your path is in double quotes this special meaning is preserved, which is noticable if you look at the file path shown within the error:

 

Warning: file_get_contents(C:\eaahmpg\eatc7402\www\stations\Sydney\code able_data.txt) [function.file-get-contents]: failed to open stream: Invalid argument in C:\eaahmpg\eatc7402\www\php\simplehtmldom\simple_html_dom.php on line 39

 

You can either use single quotes, in which "\t" will not be converted to a tab-character, or escape it with a second backslash.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.