Capture remote picture pictures and replace picture address codes _php Tutorials

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.