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

smarty now displays various writing methods of word count_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:46:50
Original
986 people have browsed it

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...
source:php.cn
Statement of this Website
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
Latest Issues
smarty turns on caching garbled characters
From 1970-01-01 08:00:00
0
0
0
Why does tp use smarty template? ?
From 1970-01-01 08:00:00
0
0
0
How do you use smarty to integrate laravel5?
From 1970-01-01 08:00:00
0
0
0
Two ways to install smarty
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template