array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.wordwrap.php', 1 => 'wordwrap', ), 'up' => array ( 0 => 'ref.strings.php', 1 => 'String 関数', ), 'prev' => array ( 0 => 'function.vsprintf.php', 1 => 'vsprintf', ), 'next' => array ( 0 => 'changelog.strings.php', 1 => '変更履歴', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/strings/functions/wordwrap.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)
wordwrap — 指定した文字数で文字列を分割する
$string
,$width
= 75,$break
= "\n",$cut_long_words
= false
指定した文字数で、指定した文字を用いて文字列を分割します。
受け取った文字列を指定した長さで分割したものを返します。
例1 wordwrap() の例
<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "<br />\n");
echo $newtext;
?>
上の例の出力は以下となります。
The quick brown fox<br /> jumped over the lazy<br /> dog.
例2 wordwrap() の例
<?php
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);
echo "$newtext\n";
?>
上の例の出力は以下となります。
A very long wooooooo ooooord.
例3 wordwrap() の例
<?php
$text = "A very long woooooooooooooooooord. and something";
$newtext = wordwrap($text, 8, "\n", false);
echo "$newtext\n";
?>
上の例の出力は以下となります。
A very long woooooooooooooooooord. and something