PDA

View Full Version : [PHP] Word Wrap Source Code



Yeldarb
February 26th, 2005, 01:00 PM
Is there a way to word wrap source code in PHP? I'm withdrawing information from a database and it looks fine on the page, but I'm just the kind of person that likes to keep my source code neat. So it's bothering me that it displays the entire post as one line.

Sorry if that was a bad explanation of my problem, but here, this should help:
http://yeldarb.servehttp.com/blog/

I want the line "This is an entry..." to look more like the commented out text. I don't want it all as one long line, but rather a series of shorter lines. Is there a function to do this or should I attmept to write my own?

Thanks :D

fluid_tw0
February 26th, 2005, 01:10 PM
wrap 'string' to another line if it exceeds given 'width'

echo wordwrap ($string, $width, "\n");

Yeldarb
February 26th, 2005, 01:14 PM
Sweet!
Thanks

Will $width break up a word in the middle?
IE if the width is 2 and I have "blah"
Willl it make it "bla\nh"?

Edit: No, it doesn't. I love PHP :D

fluid_tw0
February 26th, 2005, 01:19 PM
yep

to avoid that, use

echo wordwrap ($string, $width, "\n", 1);