PHP String nl2br() 函數(shù)
PHP的字符串nl2br()是預(yù)定義函數(shù),用于在字符串中的所有換行符之前插入HTML換行符。愛掏網(wǎng) - it200.com它返回在所有換行符(\r\n, \n\r, \n 和 \r)
之前的字符串,帶有<br \>
或<br>
。愛掏網(wǎng) - it200.com
nl2br(string,xhtml);
參數(shù) | 描述 | 是否必需 |
---|---|---|
string | 指定輸入字符串 | 必需 |
xhtml | 布爾值,是否使用XHTML兼容的換行符。愛掏網(wǎng) - it200.comTrue-默認(rèn)。愛掏網(wǎng) - it200.com插入 .False-插入 |
可選 |
示例1
<?php
echo "Your string is: Hello .\ n PHP. \ n Javatpoint"."<br>";
echo "By using 'nl2br()' function:".nl2br(" Hello .\nPHP.\n Javatpoint");
?>
注意:通過使用 ‘is_xhtml’ 參數(shù)生成有效的HTML標(biāo)記。愛掏網(wǎng) - it200.com
輸出:
Your string is: Hello .\ n PHP. \ n Javatpoint
By using 'nl2br()' function: Hello .
PHP.
Javatpoint
示例2
<?php
echo "Your string is: Welcome \ r\ n We are learning PHP"."<br>";
echo "By using 'nl2br()' Function: ".nl2br("\n Welcome\r\nWe are learning PHP", false);
?>
輸出:
Your string is: Welcome \ r\ n We are learning PHP
By using 'nl2br()' Function:
Welcome
We are learning PHP
示例3
<?php
str = "This\r\nis\n\ra\nPHP Tutorial\r";
echo "By using 'nl2br()' Function:".nl2br(str);
?>
輸出:
By using 'nl2br()' Function:This
is
a
PHP Tutorial
聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。