PHP wordwrap() 函數
實例
按照指定長度對字串進行折行處理:
	<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
定義和用法
wordwrap() 函數按照指定長度對字串進行折行處理。
注釋:該函數可能會在行的開頭留下空格。
語法
wordwrap(string,width,break,cut)
| 參數 | 描述 | 
|---|---|
| string | 必需。規定要進行折行的字串。 | 
| width | 可選。規定最大行寬度。默認是 75。 | 
| break | 可選。規定作為分隔符號使用的字元(字串斷開字元)。默認是 "\n"。 | 
| cut | 可選。規定是否對大於指定寬度的單詞進行折行: 
 | 
技術細節
| 返回值: | 如果成功,則返回折行後的字串。如果失敗,則返回 FALSE。 | 
|---|---|
| PHP 版本: | 4.0.2+ | 
| 更新日誌: | 在 PHP 4.0.3 中,新增了 cut 參數。 | 
更多實例
實例 1
使用所有的參數:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n",TRUE);
?>
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n",TRUE);
?>
實例 2
對字串進行折行:
	<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15);
?>
上面代碼的 HTML 輸出如下(查看源代碼):
	<!DOCTYPE html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
<html>
<body>
An example of a
long word is:
Supercalifragulistic
</body>
</html>
上面代碼的流覽器輸出如下:
An example of a long word is: Supercalifragulistic 
 PHP String 參考手冊
 PHP String 參考手冊
			