nl2br

All linebreaks will be converted to <br /> tags in the given variable. This is equivalent to the PHP nl2br() function.

會將變數內的斷行符號改成 <br /> 標籤,此函式同於 PHP nl2br() 函式。

Example 5-13. nl2br

<?php

$smarty
= new Smarty;
$smarty->assign('articleTitle', "Sun or rain expected\ntoday, dark tonight");
$smarty->display('index.tpl');

?>

Where index.tpl is:

其中 index.tpl 的內容為:

{$articleTitle|nl2br}

This should output:

輸出結果為:

Sun or rain expected<br />today, dark tonight