I am using this
$lines = explode(PHP_EOL, trim($text));
to split $text into an array of lines so i can display like this:
foreach ($lines as $line) {
echo $line;
}
but now i want to test the lenght of each $line and if lenght is over 50 chars i want to split each line in multiple of 50 chars.
How can i do this and keep all lines in the $lines array ?
I need a way to test each line or explode it using explode( wordwrap($line), 50 ); and then re-build the $lines array so i can cycle all lines again.
As I am not a coder I do not know how to insert new lines in the array if one line must be split in several pieces of 50 chars.
Hope you understand my question.
Thanks.
This is precisely what
chunk_splitis made for:This’ll break your
$lineinto multiple lines of 50 characters each.Update after the OP specified that he wants to split the lines into individual elements in the array:
See it here in action: http://viper-7.com/eRgm6p