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.
How can I handle the warning of file_get_contents() function in PHP?
Step 1: check the return code: if($content === FALSE) { // handle error here... }
Step 2: suppress the warning by putting an error control operator (i.e. @
) in front of the call to file_get_contents():$content = @file_get_contents($site);
Wordpress simple_html_dom.php admin page
I was able to solve this by looking at file_get_contents(): stream does not support seeking / When was PHP behavior about this changed?
On line 75 of simple_html_dom.php:$contents = file_get_contents($url, $use_include_path, $context, $offset);
I removed the reference to $offset:$contents = file_get_contents($url, $use_include_path, $context);
No my page works fine. Not taking liability for anything else it breaks! :)
Handle errors of file_get_contents()
Put an @
in front of file_get_contents
and then check if $contents === false;
$contents = @file_get_contents($url, $use_include_path, $context, $offset);
if ($contents === false) {
//Something went wrong.
}
EDIT: The @
suppresses the error from being dumped out. Uncaught Error: Call to undefined function get_file_html()
You can use str_get_html()
with the response from the curl request you have, so the code would look something like...
include "simple_html_dom.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://in.tradingview.com/symbols/NSE-TCS/");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$html = str_get_html($response);
foreach($html->find('a') as $element) {
echo $element->href . " -> " . $element->plaintext .'<br>';
}
Related Topics
Use PHP to Check If Page Was Accessed with Ssl
Resource Interpreted as Image But Transferred with Mime Type Text/HTML - Magento
Callback Function Return Return($Var & 1)
How to Deal with "Method Not Found in Class" Warning for Magically Implemented Methods
PHP MySQL Query Where X = $Variable
How to Add 5 Minutes to Current Datetime on PHP < 5.3
PHP Splitting an Array into Two Arrays - Keys Array and Values Array
Are There Any PHP Docblock Parser Tools Available
How to Use Etags in a PHP File
Facebook Graph API - Friends Using Application
Adding an Additional Custom Field in Woocommerce Edit Account Page
Possible to View PHP Code of a Website
Print a Webpage to PDF Document Using PHP
Flip (Transpose) the Rows and Columns of a 2D Array Without Changing the Number of Columns