Home > Backend Development > PHP Tutorial > 请问下面php问什么会出错

请问下面php问什么会出错

WBOY
Release: 2016-06-23 13:47:06
Original
834 people have browsed it

我就是想把 hao123的图片全都用正则匹配出来,然后再用file_get_contents()函数获取远程图片到字符串 然后再写入到文件达到下载的目的!但是file_get_contents()函数 不知道问什么匹配不了正则匹配回来的url,请大家帮忙解答下,非常感谢。
代码如下:
$str=file_get_contents("http://www.hao123.com");

preg_match_all('/\请问下面php问什么会出错/i',$str,$images);

foreach($images[1] as $key => $img)
{
$filename=$key.".png";
$imgs=file_get_contents(trim($img));
file_put_contents($filename,trim($imgs));
}

错误代码:
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


回复讨论(解决方案)

多个一对 "   改成

preg_match_all('/\

\"+(\S*)\"+
Copy after login
Copy after login
.*?\>/i',$str,$images);





多个一对 " 改成

preg_match_all('/\

\"+(\S*)\"+
Copy after login
Copy after login
.>/i',$str,$images);


preg_match_all('/\请问下面php问什么会出错/i',$str,$images);

非常感谢啊! 我说的吗 子模式中多了个引号 非常感谢 哈哈

source:php.cn
Previous article:Discuz是如何封装数据库的 Next article:symfony框架,怎么配置默认的mysql数据库
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Latest Issues
Related Topics
More>
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template