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

親自試一試

同類函數
  • 刪除字符串末端的空白字符(或者其他字符) rtrim

    rtrim

    刪除字符串末端的空白字符(或者其他字符)
  • 將字符串拆分為較小的塊 chunk_split

    chunk_split

    將字符串拆分為較小的塊
  • 根據指定格式解析輸入的字符 sscanf

    sscanf

    根據指定格式解析輸入的字符
  • 使用一個字符串分割另一個字符串為數組 explode

    explode

    使用一個字符串分割另一個字符串為數組
  • 計算字符串的md5哈希值 md5

    md5

    計算字符串的md5哈希值
  • 將帶引號的可打印字符串轉換為8位字符串 quoted_printable_decode

    quoted_printable_decode

    將帶引號的可打印字符串轉換為8位字符串
  • str_replace的不區分大小寫的版本 str_ireplace

    str_ireplace

    str_replace的不區分大小寫的版
  • 計算字符串的sha1哈希值 sha1

    sha1

    計算字符串的sha1哈希值