php - str_split without word-wrap -
i'm looking fastest solution, split string parts, without word-wrap.
$strtext = "the quick brown fox jumps on lazy dog"; $arrsplit = str_split($strtext, 12); // result: array("the quick br","own fox jump","s on l","azy dog"); // better: array("the quick","brown fox","jumps on the","lazy dog");
you can use wordwrap()
, fed explode()
, using newline character \n
delimiter. explode()
split string on newlines produced wordwrap()
.
$strtext = "the quick brown fox jumps on lazy dog"; // wrap lines limited 12 characters , break // them 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" }
Comments
Post a Comment