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}.