(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