PHP 中的 nl2br() 函数

phpprogrammingserver side programming更新于 2025/8/9 7:07:17

nl2br() 函数会在字符串的所有换行符前插入 HTML 换行符。换行符通常用以下 − 表示。


  • \r
  • \r

  • \r

语法

nl2br(str, xhtml)

参数

  • str  − 需要检查的字符串

  • xhtml  −布尔值,指示是否使用 XHTML 兼容的换行符

    • TRUE 减号插入
      。这是默认值。

    • FALSE 减号插入

返回

nl2br() 函数返回转换后的字符串。

示例

下面是一个例子 −

<?php
   echo nl2br("This has multiple 
lines
here!",false); ?>

输出

This has multiple
lines
here!

示例

下面是一个例子 −

<?php
   echo nl2br("This is\r
demo text!", false); ?>

输出

This is
demo text!

相关文章