Get Smarty

Donate

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Shop for 2018 World Cup Football Boots Online sale at guthjcc.com

Browse best 2018 world cup soccer cleats and shoes from SoccerAzteca.com

Advertisement

wordwrap

限制一行字符的长度(自动换行),默认是80个字符长度。 可选的第二个参数,可自定义换行字符,默认换行字符是 "\n"。 默认情况下,是根据单词来换行的,也就是按英文语法的自动换行。 如果你希望按照字符来换行(边界的单词将拆开),那么可以设置 可选的第三个参数为TRUE,效果与PHP函数wordwrap()一样。

参数顺序 类型 必选参数 默认值 说明
1 integer No 80 限定一行的长度。
2 string No \n 换行符号
3 boolean No FALSE 设置按单词换行(FALSE),或者按字符换行(TRUE)。

Example 5.24. wordwrap


<?php

$smarty->assign('articleTitle',
                "Blind woman gets new kidney from dad she hasn't seen in years."
               );

?>

   

模板:


{$articleTitle}

{$articleTitle|wordwrap:30}

{$articleTitle|wordwrap:20}

{$articleTitle|wordwrap:30:"<br />\n"}

{$articleTitle|wordwrap:26:"\n":true}

   

输出:


Blind woman gets new kidney from dad she hasn't seen in years.

Blind woman gets new kidney
from dad she hasn't seen in
years.

Blind woman gets new
kidney from dad she
hasn't seen in
years.

Blind woman gets new kidney<br />
from dad she hasn't seen in<br />
years.

Blind woman gets new kidn
ey from dad she hasn't se
en in years.

   

参见 nl2br{textformat}.

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 0 plus 0? (Are you human?)

Advertisement