PHP获取内容中的第一张图片
分类:PHP函数库
时间:2021-04-20
浏览:413
//获取内容中的第一张图片 if (!function_exists('rand_post_first_pic')) { function rand_post_first_pic($content){ $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; preg_match_all($pattern,$content,$matchContent); if(isset($matchContent[1][0])){ return $matchContent[1][0]; }else{ return "https://mctool.wangmingchang.com/api/api/sinaimg/t/large/sid/007goYVsgy1g5m2rdby9hj30ku0am74j";//在相应位置放置一张命名为no-image的jpg图片 } } }
本站文章如未注明出处则为原创,转载请注明出处,如有侵权请邮件联系站长