|
...
|
...
|
@@ -1588,4 +1588,27 @@ if (!function_exists('httpGetSsl')) { |
|
|
|
$result = json_decode($res, true);
|
|
|
|
return is_array($result) ? $result : $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :截取自付出啊
|
|
|
|
* @name :truncate_words
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/9/22 14:46
|
|
|
|
*/
|
|
|
|
function truncate_text($text, $limit = 300) {
|
|
|
|
// 长度小于限制直接返回
|
|
|
|
if (mb_strlen($text, 'UTF-8') <= $limit) {
|
|
|
|
return $text;
|
|
|
|
}
|
|
|
|
// 先取前 $limit 个字符
|
|
|
|
$truncated = mb_substr($text, 0, $limit, 'UTF-8');
|
|
|
|
// 如果这一段包含空格(说明有英文单词),尽量在最后一个空格处截断
|
|
|
|
$lastSpace = mb_strrpos($truncated, ' ', 0, 'UTF-8');
|
|
|
|
if ($lastSpace !== false) {
|
|
|
|
// 在最后一个空格处截断,避免英文单词被截断
|
|
|
|
$truncated = mb_substr($truncated, 0, $lastSpace, 'UTF-8');
|
|
|
|
}
|
|
|
|
return $truncated;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|