I am making a script which works individually but I am looking for all details of corresponding image like alt
, title
and image src
details. I have written this:
$websitelink='http://www.wallsave.com/wallpaper/1920x1200/houses-colorful-walpapers-history-156851.html';
$str = file_get_contents($websitelink);
if(strlen($str)>0) {
preg_match_all("/< *img[^>]*src *= *[\"\']?([^\"\']*)/i",$str,$src);
preg_match_all("/< *img[^>]*alt *= *[\"\']?([^\"\']*)/i",$str,$alt);
preg_match_all("/< *img[^>]*title *= *[\"\']?([^\"\']*)/i",$str,$title);
foreach ($src[1] as $srci) {
$imgsrc=$srci.'</br>';
}
foreach ($alt[1] as $alti) {
$altimg=$alti.'</br>';
}
foreach ($title[1] as $titlei) {
$titleimg= $titlei.'</br>';
}
$alt_title_src=$altimg.$imgsrc.$titleimg.'</br>';
echo $alt_title_src;
}
It does not work any idea or xpath will be better.