Ec (2); & lt ;? Phpphp to achieve remote image acquisition this program is a beginner, you can freely change the use of any problems or any improvements and optimizations, but also hope to share with me QQ: 297535861 with you progress. 2007-12-26functionstr_substr ($ str, $ statr, $ end) {string truncation Function & nbsp; $ xstrpos ($ str, $ statr); & script ec (2); script
// This program is for beginners. You can change it at will.
// If you have any questions or have any improvements or optimizations, please share QQ: 297535861 with me.
// Progress with you.
// 2007-12-26
Function str_substr ($ str, $ statr, $ end) {// string truncation function
$ X = strpos ($ str, $ statr );
Return substr ($ str, $ x + strlen ($ start), strpos ($ str, $ end)-$ x + strlen ($ end ));
}
//////////////////////////////////////// //////////
$ Url = "[url = http://www.xxxxxxx.xxx/xxx?http://www.xxxxxxx.xxx/xxx"; // [/url]: Set the data collection content. After uploading this sentence, the connection is automatically added. Remove it.
$ Str = file_get_contents ($ url); // file_get_contents -- read the entire file into a string
$ Start = '#######'; // unique in the last html page before the content is intercepted
$ End = '########'; // The Last html page after the content is intercepted is unique.
$ Content = str_substr ($ str, $ start, $ end );
// Echo $ content; // test the collected content
Echo '';
//////////////////////////////////////// ///////////
$ Img_array = array ();
$ Content1 = stripslashes ($ content); // The stripslashes function removes the escape characters in the string.
If (get_magic_quotes_gpc () $ content1 = stripslashes ($ content1 );
// Echo $ content1; // the content of the article has been processed.
Preg_match_all ("/(src | SRC) =" (http ://(. + )/(. + ). (gif | jpg | jpeg | bmp | png)/isU ", $ content1, $ img_array, PREG_PATTERN_ORDER); // The regular expression matches all the images and puts them in the array $ img_array, = The matching rule can be rewritten according to the specific situation. This is not universally applicable. I hope that the expert will give a matching =
$ Img_array = array_unique ($ img_array [2]); // array_unique -- removes duplicate values from the array. $ img_array [2] is not clear until now, the conjecture may be that a group in a two-dimensional array is taken out.
// Print_r ($ img_array); // test the matched content
Set_time_limit (0); // specifies the maximum execution time.
// Start to save the image in the matching content, modify the name and save it in the local folder
Foreach ($ img_array as $ key => $ value) {// use a loop statement to process the matched array content (image) one by one
If (file_get_contents ($ value) $ get_file = file_get_contents ($ value); // get the image. Use file_get_contents to get the file.
Else dir ("error ");
$ Filetime = time (); // get the timestamp
$ Filepath = "pic2/". date ("Ym", $ filetime). "/"; // path directory for saving images
! Is_dir ($ filepath )? Mkdir ($ filepath): null; // If the directory does not exist, create a directory. Note: You must have the corresponding directory permission.
$ Filename = date ("YmdHis", $ filetime ). rand (100,999 ). '. '. substr ($ value,-3, 3); // generate a file name. rand (100,999) is used to prevent duplicate file names.
$ Fp = @ fopen ($ filepath. $ filename, "w"); // open the file in write mode
@ Fwrite ($ fp, $ get_file );//
Fclose ($ fp); // finished, ha
$ Content1 = preg_replace ("/". addcslashes ($ value ,"/"). "/isU", "pic2 /". date ("Ym", $ filetime ). "/". $ filename, $ content1); // Replace the image address in the article by the way.
Echo $ value. '=>'. 'pic2/'. date ('ym', $ filetime).'/'. $ filename .'
'; // Test whether the path is normal before and after image copying.
}
Echo '';
Echo $ content1; // save $ content1 to the database.
?>