wordwrap()
Insert a linefeed after so many characters. Generally used to force a block of text not to extend past a certain number of characters. By default it will insert a linefeed at each 75 characters.
A typical use is to wrap the text in an email message body.
$text = "My tux was at the cleaners. My car broke down. I couldn’t get a cab. There was an earthquake. An enormous flood! It’s not my fault!"; echo wordwrap($text, 25); /* My tux was at the cleaners. My car broke down. I couldn’t get a cab. There was an earthquake. An enormous flood! It’s not my fault! */ // Specify the break parameter: // <br> is useful for HTML output, // or use anything for instant comic gold! echo wordwrap($text, 25, " MONKEY "); /* My tux was at the MONKEY cleaners. My car broke MONKEY down. I couldn’t get a MONKEY cab. There was an MONKEY earthquake. An enormous MONKEY flood! It’s not my fault! */
As you can see by that last example, wordwrap(), while commonly and by default used to wrap text, in truth inserts a string at a certain points in a string of text.
Set the fourth parameter to TRUE in order to force the break should a line contain no white space before the number of characters is met
$text = "I know how to spell onomatopoeia"; echo wordwrap($text, 7, "\n"); /* I know how to spell onomatopoeia */ echo wordwrap($text, 7, "\n", true); /* I know how to spell onomato poeia */
