I've made as script using file_get_html. I'm now transfering it to a Wordpress site, and it doesn't seem to work.
Just trying to use it in a admin plugin.
Snippet below:
require('includes/simple_html_dom.php');
if (isset($_POST['submit_updateColors'])) {
$qGetBrands = $mysqli->query("SELECT ... ");
while ($rowBrands = $qGetBrands->fetch_assoc()) {
$brandId = $rowBrands['cl_brand_Id'];
$url = "https://www.url.com". $rowBrands['cl_brand_url'];
$html = file_get_html($url);
$html->find('div[class=col-md-1p5]');
foreach($html->find('div[class=col-md-1p5]') as $brandColors) {
foreach ($brandColors->find('h3') as $brandColor) {
$p_brandColor = $brandColor->innertext;
}
foreach ($brandColors->find('img') as $ColorImg) {
$p_ColorImg = $ColorImg->src;
}
echo $p_brandColor ." <br />";
echo $imgName['basename'] ." <br /> <br />";
}
}
}
After while have started: echo "I'm here!!!"
Results: "I'm here!!!"
After first foreach: echo "I'm here!!!"
Results: Nothing
After $html = file_get_html($url);: echo "Result: ".$html;
Results: Nothing, not even showing "Result"
Error messages:
Fatal error: Uncaught Error: Call to a member function find() on boolean in /home/xxx/public_html/wp-content/plugins/Farbkarte/index.php:67 Stack trace: #0 /home/xxx/public_html/wp-includes/class-wp-hook.php(286): main_init('') #1 /home/xxx/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 /home/xxx/public_html/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #3 /home/xxx/public_html/wp-admin/admin.php(224): do_action('toplevel_page_f...') #4 {main} thrown in /home/xxx/public_html/wp-content/plugins/Farbkarte/index.php on line 67
I have no idea how to proceed, and would love to get some help! Outside wordpress, it works perfectly.
I hope I havent removed too much informaton.
Thanks in advance!
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! :)
Moving my earlier comment and some more hints here.
A good start would be to enable error reporting with
error_reporting(E_ALL);
ini_set('display_errors', 1);
Start from there.. I suspect that some includes are missing and you have to use the global $db object to access the DB in WP.
Looking at your errors - apparently, $html
variable is boolean and not a htmlDOM object. According to this, file_get_html()
returns false, if fetched content is empty or exceeds MAX_FILE_SIZE.
Check if the URL you are retrieving really exists, you have rights to access it, and MAX_FILE_SIZE is set correctly