限制字符串长度 [英] Limit String Length
本文介绍了限制字符串长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方法来限制php中的字符串,如果字符串太长,则在末尾添加....
I'm looking for a way to limit a string in php and add on ... at the end if the string was too long.
推荐答案
您可以使用类似于以下内容的东西:
You can use something similar to the below:
if (strlen($str) > 10)
$str = substr($str, 0, 7) . '...';
这篇关于限制字符串长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文