$fileurl = "http://www.china.com.cn/info/digi/2010-01/23/content_19293274.htm";
function take_img($str)
{
$ereg = '/http:\/\/.*(\.(jpg)|(gif)|(jpeg))/iU';
if(preg_match_all($ereg,$str,$r))
{
$array = $r[0];
return $array;
}
else
{
return false;
}
}
ob_start();
$webcontent = file_get_contents($fileurl);
$needstr = explode("<!--enpcontent-->",$webcontent);
$needstr = explode("<!--/enpcontent-->",$needstr[1]);
$contentstr = $needstr[0];
$imgarr = take_img("$contentstr");
//print_r($imgarr);
//$imgfirst = ob_get_contents($imgarr[0]);
/*$imgurl = $imgarr[0];
$imgname = basename($imgurl);
readfile($imgurl);
$data = ob_get_contents();
echo $imgname;
$fimg = fopen($imgname,'w');
fwrite($fimg,$data);
fclose($fimg);
*/
foreach($imgarr as $key => $imgurl)
{
$imgname = basename($imglist);
$contentstr = str_replace($imgurl,$imgname,$contentstr);
//$imgurl.=$imglist;
readfile($imgurl);
$immdata[]= ob_get_contents();
}
ob_end_clean();
foreach($imgarr as $Key => $imgurl)
{
$imgname = basename($imgurl);
$fimg = fopen($imgname,w);
fwrite($fimg,$imgdata[$key]);
fclose($fimg);
}