Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

str_get_html doesn't work and return blank

Tags:

php

I got a blank screen after I run below code

<?php include('simple_html_dom.php');
$html = getSslPage('https://www.reddit.com/r/nottheonion/comments/3aev89/kim_jongun_claims_to_have_cured_aids_ebola_and/');


function getSslPage($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

$html = str_get_html($html);

echo $html;

the hardest part of debugging it is it work sometime with other url. I wonder why coz the pages have the same DOM structure. Anyone have idea why is it happening?

like image 829
Jennifer Jackson Avatar asked Aug 01 '26 02:08

Jennifer Jackson


1 Answers

It is because the html string is too large and simple_html_dom has a maximum limit that it can parse. Here's what you can do to increase the limit.

Open the simple_html_dom.php and change this line

define('MAX_FILE_SIZE', 6000000);

to something more.. Try

define('MAX_FILE_SIZE', 60000000); // add a zero at the end

This should solve the problem. Let me know, if that's not the case.

like image 114
Vishwa Avatar answered Aug 02 '26 16:08

Vishwa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!