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


nl2br

(PHP 4, PHP 5)

nl2br在字符串所有新行之前插入 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

Example #2 使用 is_xhtml 生成合法的 HTML 标记

<?php
echo nl2br("Welcome This is my HTML document"false);
?>

以上例程会输出:

Welcome<br>
This is my HTML document

更新日志

版本 说明
5.3.0 新增可选的 is_xhtml 参数。
4.0.5 nl2br() 成为 XHTML 兼容的操作。所有的旧版本都会在 string 的新行之前插入 '<br>' 而不是 '<br />'。

参见


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3