假设我们有一个字符串patterns also provide us a common vocabulary to describe solutions
。
我们substr()
这个字符串,所以我们有patterns also provide us a common vocabulary to desc
。
如何将最后一个字符串剪切到patterns also provide us a common vocabulary to
?
我的方法是:
$text = mb_substr($new['text'], 0, 100);
if(mb_substr($text, -1) != ' ') {
$text_expl = explode(' ', $text);
$text = implode(' ', array_splice($text_expl, 0, -1)) . ' ...';
}
有更好的东西吗?
也许正则表达式或一些 PHP 内置函数可以做类似的事情?