Home > php教程 > php手册 > body text

smarty现在显示字数的各种写法

WBOY
Release: 2016-06-13 10:45:21
Original
969 people have browsed it

 

是否有限制显示字数的功能啊

有!用truncate

从字符串开始处截取某长度的字符.默认是80个.

你也可以指定第二个参数作为追加在截取字符串后面的文本字串.该追加字串被计算在截取长度中。

默认情况下,smarty会截取到一个词的末尾。

如果你想要精确的截取多少个字符,把第三个参数改为"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...

 

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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template