Home  >  Article  >  Backend Development  >  Introduction to the usage of parsing smarty interception string function truncate_PHP tutorial

Introduction to the usage of parsing smarty interception string function truncate_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:04:45904browse

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

truehttp: //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