Categories
PHP Tips & Tutorials

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

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.

By Yang Yang

Hello, I'm Yang. I build online businesses that please people. Want to join in and post some useful articles on Kavoir.com? Shoot me a message.

2 replies on “PHP: Wrap Long Lines | Insert Line Breaks into a Long String”

gooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooood help

Comments are closed.