Home  >  Article  >  Backend Development  >  smarty now displays various writing methods of word count_PHP tutorial

smarty now displays various writing methods of word count_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:46:50948browse

Is there a function to limit the number of displayed characters?

have! Use truncate

Cut a certain length of characters from the beginning of the string. The default is 80.

You can also specify the second argument as a text string to be appended to the intercept string. The appended string is calculated into the intercept length.

By default, smarty will truncate to the end of a word.

If you want to intercept exactly how many characters, change the third parameter to "true"

CODE:

index.php:

$smarty =new Smarty;

$smarty->assign('articleTitle','Two Sisters Reunite after Eighteen Years at CheckoutCounter.');

$smarty->display('index.tpl');

www.2cto.com

index.tpl:

{$articleTitle}

{$articleTitle|truncate}

{$articleTitle|truncate:30}

{$articleTitle|truncate:30:""}

{$articleTitle|truncate:30:"---"}

{$articleTitle|truncate:30:"":true}

{$articleTitle|truncate:30:"...":true}

OUTPUT:

Two Sisters Reunite after Eighteen Years at Checkout Counter.

Two Sisters Reunite after Eighteen Years at Checkout Counter.

Two Sisters Reunite after...

Two Sisters Reunite after

Two Sisters Reunite after---

Two Sisters Reunite after Eigh

Two Sisters Reunite after E...

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478558.htmlTechArticleIs there a function to limit the number of displayed words? Yes! Use truncate to intercept a certain length of characters from the beginning of the string. The default is 80. You can also specify the second parameter as an append to intercept the string...
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