指定の長さに達したら、文字列を新しい行にラップします:
<?php
$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+ |
変更歴 | cut パラメータは、PHP 4.0.3で追加されました |
すべてのパラメータを使用する:
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n",TRUE);
?>
例の実行 »
新しい行に文字列をラップします:
<?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
例の実行 »