There are many functions that intercept strings in php, and php functions can also be used directly in thinkphp. This article will give you a brief introduction to the specific usage of intercept strings in the thinkPHP template, hope to help you.
The following form can be used for English characters:
Copy codeThe Code is as follows:
{$ Vo. title | substr = 0, 5}
If yesThe Chinese Character thinkphp provides msubstrThe usage is as follows:
Copy codeThe Code is as follows:
Function msubstr ($ str, $ start = 0, $ length, $ charset = "UTF-8", $ suffix = true) // use the following
{$ Vo. title | msubstr = 5, 'utf-8', true}
The msubstr function is described as follows:
Msubstr ($ str, $ start = 0, $ length, $ charset = "UTF-8", $ suffix = true)
$ Str: string to be truncated
$ Start = 0: start position, starting from 0 by default
$ Length: truncation length
$ Charset = "UTF-8": character encoding, default UTF-8
$ Suffix = true: whether the ellipsis is displayed after the truncated characters. The default value is true, and false indicates that the ellipsis is not displayed.