PHP htmlwrap() function

Description

string htmlwrap ( string str [, int width [, string break [, string nobreak]]])

Test the htmlwrap() function for yourself

The code in the textarea below will be sent through the htmlwrap() function using the following arguments:
width = 50, break = "\n", nobreak = "code pre"


Reset

Version 1.7

htmlwrap() is a function which wraps HTML by breaking long words and preventing them from damaging your layout. This function will NOT insert <br> tags every "width" characters as in the PHP wordwrap() function. HTML wraps automatically, so this function only ensures wrapping at $width characters is possible. Use in places where a page will accept user input in order to create HTML output like in forums or blog comments.

This function will not insert line breaks within HTML tags or HTML entities such as &nbsp;. It treats all HTML entities as single characters, when taking them into account for string length. It will also attempt to find logical line-break insertion points (like after periods or slashes) before inserting breaks at $width characters.

Get the Code!