用 ... 在末尾缩短字符串 [英] Shortening a string with ... on the end
本文介绍了用 ... 在末尾缩短字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有官方的 PHP 函数可以做到这一点?这个动作叫什么?
Is there an official PHP function to do this? What is this action called?
推荐答案
不,没有内置函数,但你当然可以自己构建:
No, there is no built-in function, but you can of course build your own:
function str_truncate($str, $length) {
if(strlen($str) <= $length) return $str;
return substr($str, 0, $length - 3) . '...';
}
这篇关于用 ... 在末尾缩短字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文