php获取文本中首张图片地址作为封面图

180it 2020-11-16 PM 1928℃ 0条
/**
  * [getPic description]
  * 获取文本中首张图片地址
  * @梦雨www.115cms.com
  * @param  [type] $content [description]
  * @return [type]          [description]
  */
   function getpic($content){
         if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) 
         {
           $content = html_entity_decode($content);
           preg_match_all("/<img.*>/isU",$content,$ereg);
           $img=$ereg[0][0];
           $str=$matches[3][0];
           $p="#src=('|\")(.*)('|\")#isU";
        if ( preg_match_all($p,$img,$img1)) {
           return $img1[2][0];
          }
          } else {
           $default_cover=("/public/images/default_cover.png");
           return $default_cover;
        }
 }
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php获取文本中首张图片地址作为封面图