PHP wordwrap() 函數(shù)
定義和用法
wordwrap() 函數(shù)按照指定長(zhǎng)度對(duì)字符串進(jìn)行折行處理。
如果成功,則返回折行后的字符串。如果失敗,則返回 false。
語法
wordwrap(string,width,break,cut)
參數(shù) | 描述 |
---|---|
string | 必需。規(guī)定要進(jìn)行折行的字符串。 |
width | 可選。規(guī)定最大行寬度。默認(rèn)是 75。 |
break | 可選。規(guī)定作為分隔符使用的字符(字串?dāng)嚅_字符)。默認(rèn)是 "\n"。 |
cut | 可選。規(guī)定是否對(duì)大約指定寬度的單詞進(jìn)行折行。默認(rèn)是 FALSE (no-wrap)。 |
例子
例子 1
<?php
$str = "An example on a long word is: Supercalifragulistic";
echo wordwrap($str,15)
;
?>
瀏覽器輸出:
An example on a long word is: Supercalifragulistic
HTML 源代碼:
<html> <body> An example on a long word is: Supercalifragulistic </body> </html>
例子 2
<?php
$str = "An example on a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br />\n")
;
?>
輸出:
An example on a long word is: Supercalifragulistic
例子 3
<?php
$str = "An example on a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br />\n",TRUE)
;
?>
輸出:
An example on a long word is: Supercalifragul istic