當前位置: 首頁> 函數類別大全> nl2br

nl2br

在字符串所有新行之前插入HTML 換行標記
名稱:nl2br
分類:字符串
所屬語言:php
一句話介紹:在字符串中的每個新行之前插入HTML 換行符。

實例

例子1

在字符串中的新行(\n)之前插入換行符:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">nl2br</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"One line.\nAnother line."</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

以上代碼的瀏覽器輸出:

 One line.
Another line.

以上代碼的HTML 輸入(查看源代碼):

 One line.<br />
Another line.

親自試一試

例子2

通過使用xhtml參數,在新行(\n)之前插入換行符:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">nl2br</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"One line.\nAnother line."</span> <span class="token punctuation">,</span> <span class="token constant boolean">false</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

以上代碼的瀏覽器輸出:

 One line.
Another line.

以上代碼的HTML 輸入(查看源代碼):

 One line.<br>
Another line.

親自試一試

同類函數
  • 二進制安全比較字符串開頭的若干個字符(不區分大小寫) strncasecmp

    strncasecmp

    二進制安全比較字符串開頭的若干個字符(不
  • 將特殊的HTML 實體轉換回普通字符 htmlspecialchars_decode

    htmlspecialchars_decode

    將特殊的HTML實體轉換回普通字符
  • 輸出一個字符串 print

    print

    輸出一個字符串
  • 打斷字符串為指定數量的字串 wordwrap

    wordwrap

    打斷字符串為指定數量的字串
  • 將字符串轉化為小寫 strtolower

    strtolower

    將字符串轉化為小寫
  • 返回有關字符串中使用的字符的信息-統計string 中每個字節值(0..255)出現的次數 count_chars

    count_chars

    返回有關字符串中使用的字符的信息-統計s
  • 使用反斜線轉義字符串 addslashes

    addslashes

    使用反斜線轉義字符串
  • 以千位分隔符方式格式化一個數字 number_format

    number_format

    以千位分隔符方式格式化一個數字