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反函数