當前位置: 首頁> 函數類別大全> 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.

親自試一試

同類函數
  • 反轉義一個轉義的字符串 stripslashes

    stripslashes

    反轉義一個轉義的字符串
  • 將二進制數據轉換為十六進製表示 bin2hex

    bin2hex

    將二進制數據轉換為十六進製表示
  • 返回使用htmlspecialchars() 和htmlentities() 後的轉換錶 get_html_translation_table

    get_html_translation_table

    返回使用htmlspecialchars
  • 計算兩個字符串之間的編輯距離 levenshtein

    levenshtein

    計算兩個字符串之間的編輯距離
  • 檢查字符串是否以給定的子字符串結尾 str_ends_with

    str_ends_with

    檢查字符串是否以給定的子字符串結尾
  • 二進制安全字符串比較 strcmp

    strcmp

    二進制安全字符串比較
  • implode的別名 join

    join

    implode的別名
  • 返回有關字符串中使用的字符的信息-統計string 中每個字節值(0..255)出現的次數 count_chars

    count_chars

    返回有關字符串中使用的字符的信息-統計s