当前位置: 首页> 函数类别大全> nl2br

nl2br

在字符串所有新行之前插入 HTML 换行标记
名称:nl2br
分类:字符串
所属语言:php
一句话介绍:在字符串中的每个新行之前插入 HTML 换行符。

实例

例子 1

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

<span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">nl2br</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"One line.\nAnother line."</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

以上代码的浏览器输出:

One line.
Another line.

以上代码的 HTML 输入(查看源代码):

One line.<br />
Another line.

亲自试一试

例子 2

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

<span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">nl2br</span><span class="token punctuation">(</span><span class="token string double-quoted-string">"One line.\nAnother line."</span><span class="token punctuation">,</span><span class="token constant boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

以上代码的浏览器输出:

One line.
Another line.

以上代码的 HTML 输入(查看源代码):

One line.<br>
Another line.

亲自试一试

同类函数
  • 删除字符串末端的空白字符(或者其他字符) rtrim

    rtrim

    删除字符串末端的空白字符(或者其他字符)
  • 使用“自然顺序”算法比较字符串(不区分大小写) strnatcasecmp

    strnatcasecmp

    使用“自然顺序”算法比较字符串(不区分大
  • 标记分割字符串 strtok

    strtok

    标记分割字符串
  • 使用反斜线转义字符串 addslashes

    addslashes

    使用反斜线转义字符串
  • 使用 uuencode 编码一个字符串 convert_uuencode

    convert_uuencode

    使用uuencode编码一个字符串
  • 转换十六进制字符串为二进制字符串 hex2bin

    hex2bin

    转换十六进制字符串为二进制字符串
  • 将特殊字符转换为HTML实体 htmlspecialchars

    htmlspecialchars

    将特殊字符转换为HTML实体
  • 转义元字符集 quotemeta

    quotemeta

    转义元字符集