I just want to hao123 all the pictures with a regular match, and then use the file_get_contents () function to get the remote picture to the string and then write to the file to achieve the purpose of the download! But the file_get_contents () function does not know what matches the URL of the regular match back, please help to answer under, thank you very much.
The code is as follows:
$str =file_get_contents ("http://www.hao123.com");
Preg_match_all ('/\/i ', $str, $images);
foreach ($images [1] as $key = $img)
{
$filename = $key. ". PNG ";
$imgs =file_get_contents (Trim ($img));
File_put_contents ($filename, Trim ($imgs));
}
Error code:
Warning:file_get_contents ("Http://s0.hao123img.com/res/r/image/2014-10-18/3820a8ee766ece775cd098cba2706903.png ") [Function.file-get-contents]: Failed to open stream:invalid argument in C:\AppServ\www\image.php on line 9
Warning:file_get_contents ("Http://s0.hao123img.com/res/r/image/2014-09-29/d7ae4208f3fedc3c85d27f37c258706b.png ") [Function.file-get-contents]: Failed to open stream:invalid argument in C:\AppServ\www\image.php on line 9
Reply to discussion (solution)
Multiple pairs "Change to
Preg_match_all ('/\\ ' + (\s*) \ "+.*?\>/i ', $str, $images);
Multiple pairs "Change to
Preg_match_all ('/\\ ' + (\s*) \ "+.*?\>/i ', $str, $images);
Preg_match_all ('/\/i ', $str, $images);
Thank you very much! Did I say a few more quotes in the sub-pattern thank you so much haha