让梦冬眠
封藏纷乱的梦不牵挂
© JinYon.Net
All Rights Reserved.

php获取文章第一张图片做为缩略图

/**
* 获取文章第一张图片做为缩略图
* @param $content
* @return bool|string
*/
function thumb($content){
$content = stripslashes($content);
if(preg_match_all("/(src)=([\"|']?)([^ \"'>]+\.(gif|jpg|jpeg|bmp|png))\\2/i", $content, $matches)) {
$str = $matches[3][0];
//$str = substr($str, 6);
if (preg_match('/uploads/', $str)) {
return substr($str, 9);
}
}
return '';
}

 

2017-02-27