[英]str_split without word-wrap
I'm looking for the fastest solution , to split a string into parts, without word-wrap . 我正在寻找最快的解决方案 ,来分割字符串成几部分,不自动换行 。
$strText = "The quick brown fox jumps over the lazy dog";
$arrSplit = str_split($strText, 12);
// result: array("The quick br","own fox jump","s over the l","azy dog");
// better: array("The quick","brown fox","jumps over the","lazy dog");
You actually can use wordwrap()
, fed into explode()
, using the newline character \\n
as the delimiter. 实际上,您可以使用将换行符\\n
用作分隔符的wordwrap()
,并输入到explode()
。 explode()
will split the string on newlines produced by wordwrap()
. 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"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.