当前位置:Gxlcms > PHP教程 > php保留远程图片到本地

php保留远程图片到本地

时间:2021-07-01 10:21:17 帮助过:21人阅读

php 保存远程图片到本地
     

第一种: 精确型

' : "false";

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

    function getImg($str){  
        $str = stripslashes($str);  
        $pattern = "/]*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); }

人气教程排行