php - str_split without word-wrap -


i'm looking fastest solution, string parts, without .

$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

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -