你实际上可以使用wordwrap()
函数,并将其输入到explode()
函数中,使用换行符\n
作为分隔符。 explode()
函数将在由wordwrap()
产生的换行符上拆分字符串。
$strText = "The quick brown fox jumps over the lazy dog";
// Wrap lines limited to 12 characters and break
// them into an array
$lines = explode("\n", wordwrap($strText, 12, "\n"));
var_dump($lines);
array(4) {
[0]=>
string(9) "The quick"
[1]=>
string(9) "brown fox"
[2]=>
string(10) "jumps over"
[3]=>
string(12) "the lazy dog"
}