Smarty:wordwrap

2018-10-12 15:54 更新

wordwrap

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

参数顺序类型必选参数默认值说明
1integerNo80限定一行的长度。
2stringNo\n换行符号
3booleanNoFALSE设置按单词换行(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}.

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号