php,count个字符并删除超过140个字符 [英] php, count characters and deleted what is more than 140 characters

查看:123
本文介绍了php,count个字符并删除超过140个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个PHP函数来计算短语的字符数。如果短语长度大于140字符,则此函数应删除所有其他字符,并在短语的结尾添加三个点。
例如我们有。

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"

如果这超过140个字符,那么

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

推荐答案

if(strlen($str) > 140){
   $str =  substr($str, 0, 140).'...';
}

这篇关于php,count个字符并删除超过140个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆