View Full Version : line breaks

07-18-2005, 12:35 PM
Hi...I have little problem on at moment....my problem is i'm trying to build a php data driven website.....the problem is when i display the data from the data.....its broken up my html table structure...is there anyway i can Maintain the line breaks

07-18-2005, 02:03 PM
If you mean linebreaks, for instance, like the ones created by <textarea> form fields ("\r", "\r\n" or "\n") then you can turn these into <br /> tags that will show up when you echo your HTML by using the nl2br() function, eg if you have some data in a variable called $data:

echo nl2br($data);

07-18-2005, 04:13 PM
I want to add this as well, nl2br function doesn't convert the new lines, it mearly adds a <br /> in front of it for html processing. This is most likely the function you are looking for, but beware of that aspect, I've seen a few sites that required the newlines to be destroyed (which requires either a replacement pattern (useless for this function), or a simple str_replace).