smarty truncate intercepts a string
Truncates a certain length of characters from the beginning of the string, the default length is 80
Specify the second parameter as the length of the intercepted string
By default, smarty will intercept to the end of a word.
If you need to accurately intercept how many characters, you can use the third parameter and set it to "true"
The specific usage is as follows :
Copy code The code is as follows:
//index.php $smarty = new Smarty;
$smarty->assign('articleTitle', 'Two Sisters Reunite after Eighteen Years at Checkout Counter.');
$smarty->display('index.tpl');
//index.tpl
{$articleTitle}
{$articleTitle|truncate}
{$articleTitle|truncate:30}
{$articleTitle|truncate:30:""}
{$articleTitle|truncate: 30:"---"}
{$articleTitle|truncate:30:"":true}
{$articleTitle|truncate:30:"...":true}
Output result:
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter. Reunite after
Two Sisters Reunite after—
Two Sisters Reunite after Eigh
Two Sisters Reunite after E…
http://www.bkjia.com/PHPjc/327740.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327740.htmlTechArticlesmarty truncate intercepts a string and intercepts characters of a certain length from the beginning of the string. The default length is 80. Specify the second Parameters are used as the length of the intercepted string. By default, smarty will intercept...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn