换行标记
nl2br — 在字符串所有新行之前插入 HTML 换行标记
语法
string nl2br( string $string[, bool $is_xhtml = true] )
描述
- 在字符串 string 所有新行之前插入Html标签br,并返回
参数
参数 | 描述 |
---|---|
string | 输入字符串 |
is_xhtml | 是否使用XHTML兼容换行符 |
返回值
- 返回调整后的字符串
举例
// 示例1-基本使用
echo nl2br("foo isn't\n bar");
// 结果
foo isn't
bar
// 源代码
foo isn't<br />
bar
// 示例2-设置第二个参数
echo nl2br("Welcome\r\nThis is my HTML document", true);
echo nl2br("Welcome\r\nThis is my HTML document", false);
// 结果
Welcome
This is my HTML document
Welcome
This is my HTML document
// 源代码
Welcome<br />
This is my HTML document
Welcome<br>
This is my HTML document