php,统计字符数并删除超过140个字符的内容
我需要一个 PHP 函数来计算短语的字符数。如果短语长度超过“140”个字符,则此函数应删除所有其他字符并在短语末尾添加三个点。 例如我们有。
$message= "I am what I am and you are what you are etc etc etc etc"
如果长度超过 140 个字符,那么
$message= "I am what I am and you are what you are..."
这可能吗?如何? 谢谢
I need a PHP function that will count the number of characters of a phrase. If the phrase is longer than "140" character then this function should delete all the other character and add three points at then end of the phrase.
So for example we have.
$message= "I am what I am and you are what you are etc etc etc etc"
IF this is longer than 140 characters, then
$message= "I am what I am and you are what you are..."
Is this possible? How?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果你想“单词敏感”(即不在单词中间中断),你可以使用
wordwrap()
。If you want to be "word sensitive" (i.e. not break in the middle of the word), you can use
wordwrap()
.此变体将在必要的字符集(例如 utf-8)下正确工作,并且将尝试按空格剪切,以免破坏单词:
This variant will work correct with necessary charset (e.g. utf-8), and will try to cut by space, to not break words:
那将是:
That would be:
这是我经常使用的一个功能,
您可以将默认长度更改为您想要的任何长度
This is a function that i use quite often
you can change the default length to anything you want