nl2br

  PHP中  

 在字符串所有新行之前插入 HTML 换行标记

说明

string nl2br ( string $string [, bool $is_xhtml = true ] )

在字符串 string 所有新行之前插入 '<br />' 或 '<br>',并返回。

参数

 

string

输入字符串。

is_xhtml

是否使用 XHTML 兼容换行符。

返回值

返回调整后的字符串。

范例

 

Example #1 nl2br() 使用范例

<?php
echo nl2br("foo isn't  bar");
?>

以上例程会输出:

foo isn't<br />
 bar



smarty中

将变量值中的" "回车全部转换成HTML的 <br />。 等同于PHP的 nl2br()函数。



<?php

$smarty->assign('articleTitle',
                "Sun or rain expected
today, dark tonight"
                );

?>

   

模板:

{$articleTitle|nl2br}

   

输出:

Sun or rain expected<br />today, dark tonight
原文地址:https://www.cnblogs.com/yangcclg/p/5127474.html