PHP nl2br() 函数

PHP 教程 · 2019-01-29 18:13:44

实例

在字符串中的新行(\n)之前插入换行符:

<?php echo nl2br("One line.\nAnother line."); ?>

上面代码的浏览器输出如下:

One line.
Another line.

上面代码的 HTML 输入如下(查看源代码):

One line.<br />
Another line.

定义和用法

nl2br() 函数在字符串中的每个新行(\n)之前插入 HTML 换行符(<br> 或 <br />)。

语法


nl2br(string,xhtml)


参数 描述
string 必需。规定要检查的字符串。
xhtml 可选。一个表示是否使用兼容 XHTML 换行的布尔值:
  • TRUE- 默认。插入 <br />
  • FALSE - 插入 <br>

技术细节

返回值: 返回已转换的字符串。
PHP 版本: 4+
更新日志: 在 PHP 4.0.5 之前,该函数插入 <br>。在 PHP 4.0.5 之后,该函数插入兼容 XHTML 的 <br />。

在 PHP 5.3 中,新增了 xhtml 参数。

更多实例

实例 1

通过使用 xhtml 参数,在新行(\n)之前插入换行符:

<?php echo nl2br("One line.\nAnother line.",false); ?>

上面代码的浏览器输出如下:

One line.
Another line.

上面代码的 HTML 输入如下(查看源代码):

One line.<br>
Another line.

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

Deep Learning

Deep Learning

Ian Goodfellow、Yoshua Bengio、Aaron Courville / The MIT Press / 2016-11-11 / USD 72.00

"Written by three experts in the field, Deep Learning is the only comprehensive book on the subject." -- Elon Musk, co-chair of OpenAI; co-founder and CEO of Tesla and SpaceX Deep learning is a for......一起来看看 《Deep Learning》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具