May I ask the following PHP what will be wrong

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

  • Related Article

    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.