-3

AA Dear bro, i want to get the img src from a html page butt i have faced with error,Help please , my server show this messaage

Notice: Undefined offset: 0 in F:\xamppppp\htdocs\Arslan_Sir\img download from google.php on line 13 Notice: Array to string conversion in F:\xamppppp\htdocs\Arslan_Sir\img download from google.php on line 15 Array

my code is

<?php //this code can be pic
image from a html page   $ctual_link="https://www.google.com/search?q=9780333993385&ie=utf-8&oe=utf-8&client=firefox-b-ab"; define('DIRECTORY', '/imgg/m/');  $text = file_get_contents($ctual_link); preg_match_all('/<div class=\"image\">(.*?)<\/div>/s', $text, $out); //preg_match('/~src="(.*)"itemprop="image" \/>/',$text,$out); preg_match('~src="(.*)"\s*itemprop="image"[^>]*>~',$text,$out); //$out
= explode(' ',$out[1]); $z=trim($out[0],'"');  echo  $out;  //}      ?>
LF00
  • 27,015
  • 29
  • 156
  • 295

2 Answers2

0

Not quite sure but thinking about PHP Simple HTML DOM Parser

the example from the landing page of the library

$html = file_get_html('http://www.google.com/');

// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';
0

solved your issue you can apply this code it will help you better

<?php 
$ctual_link="https://www.google.com/search?q=9780333993385&ie=utf-8&oe=utf-8&client=firefox-b-ab";

$html = file_get_contents($ctual_link);
//Create a new DOM document
$dom = new DOMDocument;

@$dom->loadHTML($html);

$links = $dom->getElementsByTagName('img');

foreach ($links as $link){
    //Extract and show the "src" attribute of image.
    echo $link->nodeValue;
    echo $link->getAttribute('src'), '<br>';
}
 ?>
Niraj patel
  • 525
  • 4
  • 12