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

親自試一試

同類函數
  • 子字符串替換 str_replace

    str_replace

    子字符串替換
  • 將字符串轉換為數組 str_split

    str_split

    將字符串轉換為數組
  • 計算指定字符串在目標字符串中最後一次出現的位置(不區分大小寫) strripos

    strripos

    計算指定字符串在目標字符串中最後一次出現
  • 計算子字符串出現次數 substr_count

    substr_count

    計算子字符串出現次數
  • 將數字格式化成貨幣字符串 money_format

    money_format

    將數字格式化成貨幣字符串
  • 使用一個字符串分割另一個字符串為數組 explode

    explode

    使用一個字符串分割另一個字符串為數組
  • 基於區域設置的字符串比較 strcoll

    strcoll

    基於區域設置的字符串比較
  • 將邏輯順序希伯來文(logical-Hebrew)轉換為視覺順序希伯來文(visual-Hebrew) hebrev

    hebrev

    將邏輯順序希伯來文(logical-He