获取文章第一张图作为cover

This commit is contained in:
浪子
2024-05-18 18:51:07 +08:00
parent d8cf19ca6d
commit fc3d9b6890
2 changed files with 14 additions and 2 deletions
+9 -1
View File
@@ -155,4 +155,12 @@ function allwords() {
echo '全站共 '.$chars.' 字,写完一本我国著名的四大名著了!';}
elseif ($chars>1000000){
echo '全站共 '.$chars.' 字,已写一本列夫·托尔斯泰的《战争与和平》了!';}
}
}
function show_first_image($content) {
preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
// 检查是否找到了图片
if(isset($matches[1][0])){
return $matches[1][0];
}
return false; // 没有找到图片,返回 false
}