I am trying to split a 90 character long string onto three 30 length strings. I cannot simply chop the long string into three lines(worst case scenario) as words in string will split. The code I have tried is as follows(but doesn't work), please help
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$str = "test string more and more text very long string can be upto length of 90";
$line1 = $line2 = $line3 = "";
$temp = explode(" ", $str);
//var_dump($temp);
for($i=0; $i<count($temp); $i++){
if(strlen($line1) < 30){
$line1. = $temp[$i]." ";
}else if(strlen($line2) < 30) {
$line2. = $temp[$i]." ";
}else if(strlen($line3) < 30) {
$line2. = $temp[$i]." ";
}
}
//var_dump($line1);
?>
I am trying to add as many words in $line1 from $temp as possible and then to $line2 ....