在分词处截断文本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在分词处截断文本相关的知识,希望对你有一定的参考价值。
This function will truncate strings only at word breaks which can be used to show a teaser for complete article without breaking words.
// Original php code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. function myTruncate($string, $limit, $break=".", $pad="...") { // return with no change if string is shorter than $limit return $string; // is $break present between $limit and the end of the string? } } return $string; } /***** Example ****/ $short_string=myTruncate($long_string, 100, ' ');
以上是关于在分词处截断文本的主要内容,如果未能解决你的问题,请参考以下文章