Wordwrap example

Shows how to use the build-in function "wordwrap" to create line breaks by a user definied length.

// create a long text for testing:
$long_text = 'This is a long text to demonstrate the usage of the ';
$long_text .= 'wordwrap function. ';
$long_text .= 'Fooooooooooooooooobar, just fooling around';
 
// syntax: wordwrap(input string, line max. width, break chars, cut words)
$new_text = wordwrap($long_text, 15, "<br/>\n", true);
 
print $new_text;
 
/* 
The output will be:
 
This is a long<br/>
text to<br/>
demonstrate the<br/>
usage of the<br/>
wordwrap<br/>
function.<br/>
Foooooooooooooo<br/>
ooobar, just<br/>
fooling around
 
*/
Snippet Details




Sorry folks, comments have been deactivated for now due to the large amount of spam.

Please try to post your questions or problems on a related programming board, a suitable mailing list, a programming chat-room,
or use a QA website like stackoverflow because I'm usually too busy to answer any mails related
to my code snippets. Therefore please just mail me if you found a serious bug... Thank you!


Older comments:

None.