修复getDescriptionFromContent 不存在的问题

This commit is contained in:
hdm 2021-10-21 19:17:58 +08:00
parent 01140dc465
commit 08d06e9479

View File

@ -25,7 +25,26 @@ function get_login_admin($key = "")
return '';
}
}
/**
* 截取摘要
* @return bool
*/
function getDescriptionFromContent($content, $count)
{
$content = preg_replace("@<script(.*?)</script>@is", "", $content);
$content = preg_replace("@<iframe(.*?)</iframe>@is", "", $content);
$content = preg_replace("@<style(.*?)</style>@is", "", $content);
$content = preg_replace("@<(.*?)>@is", "", $content);
$content = str_replace(PHP_EOL, '', $content);
$space = array(" ", " ", " ", " ", " ");
$go_away = array("", "", "", "", "");
$content = str_replace($space, $go_away, $content);
$res = mb_substr($content, 0, $count, 'UTF-8');
if (mb_strlen($content, 'UTF-8') > $count) {
$res = $res . "...";
}
return $res;
}
/**
* PHP格式化字节大小
* @param number $size 字节数