📜  php 用点缩短字符串 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:43.924000             🧑  作者: Mango

代码示例2
function preview($text)
// we don't want new lines in our preview
$text_only_spaces = preg_replace('/\s+/', ' ', $text);
// truncates the text
$text_truncated = mb_substr($text_only_spaces, 0, mb_strpos($text_only_spaces, " ", 50));
// prevents last word truncation
$preview = trim(mb_substr($text_truncated, 0, mb_strrpos($text_truncated, " ")));
$preview."...";
}