I'm running simple html dom on php 7.1.
But the first line I can not parse html
My code
<?php
include 'simple_html_dom.php';
$html = file_get_html('http://google.com');
echo $html;
?>
The page displays nothing (white background) with the above code.
But the below code but runs:
<?php
include 'simple_html_dom.php';
//base url
$base = 'https://google.com';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);
// Create a DOM object
$html_base = new simple_html_dom();
// Load HTML from a string
$html_base->load($str);
echo $html_base;
$html_base->clear();
unset($html_base);
?>
Then, I try to get img with class below code with above code but no working:
Image html to get:
<div class="product_thumb">
<a title="Me Before You" class="image-border" href=/me-before-you-a-novel-movie-tie-in-p69988.html">
<img class=" pict lazy-img" id="det_img_00069988"
src="/images/thumbnails/product/115x/222614_me-before-you-a-novel-movie-tie-
in.jpg">
</a></div>
My Simple HTML DOM, All dont working (get no html on may page)
//* Find all images 1st code
foreach($html_base->find('img[class= pict lazy-img]') as $element)
echo '<img src="' . $element->src . '" />' . '<br>';
//* Find all images 2nd code
foreach($html_base->find('img[class= pict lazy-img]',0) as $element)
echo '<img src="' . $element->src . '" />' . '<br>';
//* Find all images 3rd code
foreach($html_base->find('img[class$=pict lazy-img]',0) as $element)
echo '<img src="' . $element->src . '" />' . '<br>';
//* Find all images 4th code
foreach($html_base->find('img[class$=pict lazy-img]',0) as $element)
echo '<img src="' . $element->src . '" />' . '<br>';