PHP wordwrap() 函數(shù)

2018-11-21 15:55 更新

PHP wordwrap() 函數(shù)

PHP String 參考手冊(cè) PHP String 參考手冊(cè)

實(shí)例

按照指定長(zhǎng)度對(duì)字符串進(jìn)行折行處理:

<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n");
?>

運(yùn)行實(shí)例 ?

定義和用法

wordwrap() 函數(shù)按照指定長(zhǎng)度對(duì)字符串進(jìn)行折行處理。

注釋:該函數(shù)可能會(huì)在行的開(kāi)頭留下空格。


語(yǔ)法

wordwrap(string,width,break,cut)

參數(shù) 描述
string 必需。規(guī)定要進(jìn)行折行的字符串。
width 可選。規(guī)定最大行寬度。默認(rèn)是 75。
break 可選。規(guī)定作為分隔符使用的字符(字串?dāng)嚅_(kāi)字符)。默認(rèn)是 "\n"。
cut 可選。規(guī)定是否對(duì)大于指定寬度的單詞進(jìn)行折行:
  • FALSE - 默認(rèn)。不折行
  • TRUE - 折行

技術(shù)細(xì)節(jié)

返回值: 如果成功,則返回折行后的字符串。如果失敗,則返回 FALSE。
PHP 版本: 4.0.2+
更新日志: 在 PHP 4.0.3 中,新增了 cut 參數(shù)。


更多實(shí)例

實(shí)例 1

使用所有的參數(shù):

<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>n",TRUE);
?>

運(yùn)行實(shí)例 ?

實(shí)例 2

對(duì)字符串進(jìn)行折行:

<?php
$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>

上面代碼的瀏覽器輸出如下:

An example of a long word is: Supercalifragulistic

運(yùn)行實(shí)例 ?


PHP String 參考手冊(cè) PHP String 參考手冊(cè)
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)