Home>Article>Backend Development> php 封存远程图片到本地

php 封存远程图片到本地

WBOY
WBOY Original
2016-06-13 13:08:40 779browse

php 保存远程图片到本地

显示远程图片:


? header('Content-Type:image/jpg'); echo file_get_contents("http://www.baidu.com/img/baidu_logo.gif"); ?>

?

第一种: 精确型

?

 php 封存远程图片到本地 
' : "false";

?

第二种:从文章中提取图片,并保存至本地

function getImg($str){ $str = stripslashes($str); $pattern = "/ php 封存远程图片到本地 ]*src\=\"(([^>]*)(jpg|gif|png|bmp|jpeg))\"/i"; //获取所有图片标签的全部信息 preg_match_all($pattern, $str, $matches); return $matches[1]; //$matches[1]中就是所想匹配的结果,结果为数组 } $str = << Two giant resource companies make up a big chunk of the Brazilian Bovespa. They are PetroBras (NYSE: PBR), with a market cap of $163.44 billion, and miner Vale (NYSE: VALE), which has a market cap of $178.95 billion. PBR shares have risen 1.47% thus far today and VALE is trading 0.77% higher at $34.03. Sony This article was originally published on Benzinga, and is republished here with permission. EOT; foreach( getImg($str) as $url) { get_photo($url); }
?
Statement:
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