array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.wordwrap.php', 1 => 'wordwrap', ), 'up' => array ( 0 => 'ref.strings.php', 1 => '字符串 函数', ), 'prev' => array ( 0 => 'function.vsprintf.php', 1 => 'vsprintf', ), 'next' => array ( 0 => 'changelog.strings.php', 1 => '更新日志', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', '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