How to use file_get_contents or file_get_html?
You are not able to specify in file_get_contents()
just to retrieve the tables.
You would have to get the return value of file_get_contents()
using:
$result = file_get_contents("urlHere");
And then analyse the $result
variable and extract what information you need to output.
file_get_contents(): stream does not support seeking / When was PHP behavior about this changed?
See file_get_contents(): stream does not support seeking PHP
You are working with a remote file. Seeking is only supported for local files.
You probably need to copy the file to your local file system before using file_get_html
. It should work fine on localhost.
Get Links with simple html dom
wrap your file_get_contents in str_get_html function
// method 1
$html = new simple_html_dom();
$html->load( file_get_contents ($url, false, $context) );
// or method 2
$html = str_get_html( file_get_contents ($url, false, $context) );
you're creating a new dom and assigning it to the variable $html, than reading the url returning the string and setting it to $html, thus overwriting your simple_html_dom instance, so when your invoking the find method you have a string instead of an object.
Good error handling with file_get_contents
Here's an idea:
function fget_contents() {
$args = func_get_args();
// the @ can be removed if you lower error_reporting level
$contents = @call_user_func_array('file_get_contents', $args);
if ($contents === false) {
throw new Exception('Failed to open ' . $file);
} else {
return $contents;
}
}
Basically a wrapper to file_get_contents
. It will throw an exception on failure.
To avoid having to override file_get_contents
itself, you can
// change this
$dom->load(call_user_func_array('file_get_contents', $args), true);
// to
$dom->load(call_user_func_array('fget_contents', $args), true);
Now you can:
try {
$html3 = file_get_html(trim("$link"));
} catch (Exception $e) {
// handle error here
}
Error suppression (either by using @
or by lowering the error_reporting level is a valid solution. This can throw exceptions and you can use that to handle your errors. There are many reasons why file_get_contents
might generate warnings, and PHP's manual itself recommends lowering error_reporting: See manual
file_get_html error, not working
Try this:
$html = str_get_html(file_get_contents($url));
Related Topics
Adding User Custom Field Value to Order Items Details
Check If Method Exists in the Same Class
How to Determine If a PHP File Is Loaded via Cron/Command Line
How to Get/Set Session_Id() or Should It Be Generated Automatically
Soapclient: How to Pass Multiple Elements with Same Name
Replace the Last Comma with an & Sign
Http Auth via PHP - PHP_Auth_User Not Set
Html2Pdf in PHP - Convert Utilities & Scripts - Examples & Demos
Php: Check If Xml Node Exists with Attribute
How to Access MySQLi Connection in Another Class on Another Page
Tcpdf and Insert an Image Base64 Encoded
Nl2Br() Equivalent in JavaScript
Is It Acceptable to Use a Mix of Object Oriented Style with Procedural Style in Coding PHP
How to Allow a User to Download a File Which Is Stored Outside of the Webroot
How to Get the Tag "<Yweather:Condition>" from Yahoo Weather Rss in PHP
How to Hide PHP File Extension Without Using .Htaccess
Difference(When Being Applied to My Code) Between Int(10) and Int(12)