nl2br反函数_PHP nl2br()函数与示例

nl2br反函数

PHP nl2br()函数 (PHP nl2br() function)

nl2br() stands for "New Line to Break", this function converts all new line characters (\n) to break tag (<br>) in the string. It can be seen by viewing the source of the HTML.

nl2br()代表 换行符 ,此函数将所有换行符( \ n )转换为字符串中的换行符( <br> )。 通过查看HTML的源代码可以看到它。

Syntax:

句法:

    nl2br(string, [xhtml]);

It accepts the string and converts returns the string with <br> tag instead of all \n (New line character).

它接受的字符串 ,并将其转换返回字符串 点击标签,而不是所有人\ n(换行字符)。

Here, second parameter xhtml is an optional parameter and it is used to either use <br> - if xhtml value is FALSE, or use <br /> - if xhtml value is TRUE. If you don't use this parameter, the default value will be TRUE.

在这里,第二个参数xhtml是可选参数,用于xbr值为FALSE时使用<br>或xhtml值为TRUE时使用<br /> 。 如果不使用此参数,则默认值为TRUE 。

Examples:

例子:

    Input: "Hello\nWorld"
    Output:
    Hello<br />
    World

PHP code:

PHP代码:

<?php
    $str = "Hello\nWorld\n";
    echo nl2br($str);

    $str = "My\nName\nis\nIncludeHelp\n";
    echo nl2br($str);

    $str = "Hello\nWorld\n";
    echo nl2br($str,FALSE);

    $str = "My\nName\nis\nIncludeHelp\n";
    echo nl2br($str,FALSE);    
?>

Output

输出量

Hello<br />
World<br />
My<br />
Name<br />
is<br />
IncludeHelp<br />
Hello<br>
World<br>
My<br>
Name<br>
is<br>
IncludeHelp<br>


翻译自: https://www.includehelp.com/php/nl2br-function-with-example.aspx

nl2br反函数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值