Hey, how do you limit the length of a line in php? Like I only want a line to have 40 chars even if they are all put together.
Test: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$rest = substr ("abcdef", 1, 3); // returns "bcd"
So in your case:
$leftover = substr($Test, 0, 40);
J.
Umm, cool, but I tried a while loop with that command but it didn't work. I want it to print out the entire message but at only 50 per line.
try wordwrap .
It will even split it so that it wont split in the middle of a word. you can specify if you want to split strictly at a specified length or use chunk_split
Thank you!
I think this can be a solution:
$s=str_repeat('a',121); echo wordwrap($s,40,'<br>',1);
Don't forget the last parameter: 1.