String 函数
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程

nl2br

(PHP 4, PHP 5)

nl2brInserts HTML line breaks before all newlines in a string

说明

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

Returns string with '<br />' or '<br>' inserted before all newlines.

参数

string

The input string.

is_xhtml

Whenever to use XHTML compatible line breaks or not (defaults to TRUE).

返回值

Returns the altered string.

范例

Example #1 using nl2br()

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

上例将输出:

foo isn't<br />
 bar

Example #2 Generating valid HTML markup using the is_xhtml parameter

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

上例将输出:

Welcome<br>
This is my HTML document

更新日志

版本 说明
5.3.0 Added the optional is_xhtml parameter.
4.0.5 nl2br() is now XHTML compliant. All older versions will return string with '<br>' inserted before newlines instead of '<br />'.

参见


String 函数
php 手册 | 脚本学堂 | 脚本编程 | 网站编程 | 系统管理 | 服务器配置 | 数据库管理 | Php教程 | python教程 | 正则表达式 | 批处理脚本 | Centos教程 | Linux基础教程