PHP: Wrap Long Lines | Insert Line Breaks into a Long String

by Yang Yang on April 23, 2009

Share This Article:
Subscribe to Kavoir: blog feed

Some strings of texts may lack necessary wraps and don’t have natural line breaks in them so that the lines are too long to read comfortably. Therefore, you want a way to insert line breaks in to the string every dozens of characters.

The php function you need is wordwrap():

$s = ' ... '; // very long single line string text
$s_wrapped = wordwrap($s, 60); // $s is wrapped by every 60 characters and evaluated to $s_wrapped

Line breaks are inserted into the original text every 60 characters.

Share This Article:
Subscribe to Kavoir: blog feed

You should also read:

{ 2 comments… read them below or add one }

Imran April 1, 2011 at 6:43 pm

gooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooood help

Reply

Yang Yang April 2, 2011 at 7:45 am

Dude, you messed it up!

Reply

Leave a Comment

Previous post:

Next post: