Now using PHP to collect remote images is very simple thing, but we have to filter the collected data, it is afraid to use the regular expression, the following program is to collect remote picture image and replace the image address code.
Capture remote picture images and replace image address codes
/*
Now using PHP tutorial to collect remote pictures is very simple thing, but we have to filter the collected data, which I am afraid to use the regular expression, the following program is to collect remote picture image and replace the image address code.
*/
$dir _date=date (' y/m/d ');//Date folder
$dir _name= "images/$dir _date";//Folder path
function mkdirm ($path)//Fetch folder name
{
if (!file_exists ($path))//Determine existence
{
Mkdirm (DirName ($path)); Returns the directory portion of the path
mkdir ($path, 0777); Create folders and Permissions
}
}
Mkdirm ($dir _name);//Create Folder
$files = file_get_contents (' http://www.ywsp.com ');
$files = ";
Image address convert $p =preg_replace ('//image//', ' http://qq.ip138.com/image/', $PG [1]);
$reg = "/]*src=" (http:/(. +)/(. +). ( JPG|GIF|BMP|BNP)) "/isu";
$img =preg_match_all ($reg, $files, $imgs);
for ($i =0; $i<>
{
echo "". $imgs [1][$i]. "
n ";
Save picture
$opts = Array (
' HTTP ' =>array (
' Header ' = ' referer:http://www.bkjia.com/rn '
)
);
$context = Stream_context_create ($opts);
Header (' Content-type:image/jpeg ');
$fileresource = @file_get_contents ($imgs [1][$i],false, $context);
$image _old.= "". $imgs [1][$i]. "". ","; Turn all URLs into a number like 1,2,3,4 first
$image _new.= "". $dir _name. " /". Mktime (). $i.". JPG "." "". ","; Turn all the new image addresses into a number like 1,2,3,4
File_put_contents ($dir _name. " /". Mktime (). $i.". JPG ", $fileresource);
Save picture
}
$image _old=substr ($image _old,0, (strlen ($image _old)-1);//Remove the last comma of the URL
$image _new=substr ($image _new,0, (strlen ($image _new)-1);//Remove the last comma of the new URL
Print_r ($p);
$image _old=explode (",", $image _old);//Split multiple
$image _new=explode (",", $image _new);//Split multiple
$files =str_replace ($image _old, $image _new, $files); Call the URL with the new image URL to replace it.
Echo $files;
http://www.bkjia.com/PHPjc/444890.html www.bkjia.com true http://www.bkjia.com/PHPjc/444890.html techarticle now using PHP to collect remote pictures is very simple thing, but we have to filter the collected data, which I am afraid to use the regular expression, the following program is to collect remote pictures ...