<?php
function extract_url($main_url){

    $cek_url = parse_url($main_url);
    $prefix_url = $cek_url['scheme'].'://'.$cek_url['host'];

    $f = fopen($main_url,"r"); 
    $inputStream = fread($f,65535); 
    fclose($f); 
    if (preg_match_all("/<img.*? src=\"(.*?)\".*?>/i",$inputStream,$matches)) { 
        foreach($matches[1] as $link){
            if(!eregi('mailto:|javascript:|ymsgr:',$link)){
                if(eregi("http://",$link)){
                    $url = $link;
                }
                else{
                    $url = $prefix_url.'/'.$link;
                }
                if(eregi('PHPSESSID',$url)){
                    $url = explode("PHPSESSID",$url);
                    $url = substr($url[0],0,-1);
                }
                $output[] = $url;
            }
        }
    }
    return $output;
}
?>




<html>
<head>
</head>
<body>
<?php

$check=extract_url("http://www.example.com");
for($i=0;$check[$i]!='';$i++)
{
echo '<img src="'.$check[$i].'"/><br><br>';
}



?>.
</body>
</html>

I m trying to fetch out all the images of the given url
but this code fetches the only some images . i need all the images so plz try to find out the error.

Edited 3 Years Ago by happygeek: fixed formatting

Instead of

$f = fopen($main_url,"r");
$inputStream = fread($f,65535);
fclose($f);

use, $inputStream = implode("",file($main_url)); The problem with your code was, it was reading only a part of the file.

Instead of
use, $inputStream = implode("",file($main_url)); The problem with your code was, it was reading only a part of the file.

Thanx a lot buddy :)

This article has been dead for over six months. Start a new discussion instead.