Wrap a Long String, Word or URL Over Multiple Lines

and like us on FB

A long string of text can often break the formatting of a page – particularly if text is rendered in a narrow table. The solution: Implement a PHP function that will wrap a string over multiple lines.

Line-wrapping is commonly used by utilizing a hyphen (a dash, actually) to divide words at the nearest breakpoint between syllables, indicating that the letters form a word fragment – not a word. In the following case, the breakpoint is defined by the container or table it is in.

If your problem can’t be managed by CSS, consider the following.

Wrap a Long String, Word or URL Over Multiple Lines

In this case, the only long ‘word’ was a URL, and it was split (hyphenated) over multiple lines within a table cell.

Depending on your needs, the PHP wordwrap function may be all that you require. If you need to break a URL, consider truncating them.