PHPワードラップ()関数
例
文字列が特定の長さに達したら、新しい行にラップします。
<?php
$str = "An example of a long word is: Supercalifragulistic";
echo wordwrap($str,15,"<br>\n");
?>
定義と使用法
wordwrap()関数は、特定の長さに達したときに文字列を新しい行にラップします。
注:この関数は、行の先頭に空白を残す場合があります。
構文
wordwrap(string,width,break,cut)
パラメータ値
Parameter | Description |
---|---|
string | Required. Specifies the string to break up into lines |
width | Optional. Specifies the maximum line width. Default is 75 |
break | Optional. Specifies the characters to use as break. Default is "\n" |
cut |
Optional. Specifies whether words longer than the specified width should be wrapped:
|
技術的な詳細
戻り値: | 成功した場合は行に分割された文字列を返し、失敗した場合はFALSEを返します。 |
---|---|
PHPバージョン: | 4.0.2 + |
変更ログ: | カットパラメータはPHP4.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
❮PHP文字列リファレンス