Text return with no line breaks

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gaz
Forum Newbie
Posts: 2
Joined: Tue Dec 14, 2010 9:12 pm

Text return with no line breaks

Post by Gaz »

Hi all :)
I'm a newbie in the world of PHP and slowly beginning to understand more and more :)

i have recently created my database and successfully created;
an input form
a search page
a csv dump
view database records

the problem i have is my search returns. one of my input fields is a text body but when it returns the data from the search it is just on big line of words and no newlines :(
now i understand about the nl2br() function but i dont know how to implement it!
where does it go?
is it on my search functions php, my form input?
im tearing my hair out on this one :banghead:

i dont want to put up a load of code here if its the wrong one so if someone can tell me where it goes i will post my code.

Sorry for being a newbie but we all start somewhere :crazy:
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Text return with no line breaks

Post by Celauran »

When you're displaying your search results, wrap the text field in nl2br.

Code: Select all

while ($row = mysql_fetch_array($result))
{
  ...
  echo nl2br($row['text']);
  ...
}
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Text return with no line breaks

Post by superdezign »

Also, if you are giving raw data, you may want to consider using the <pre> tag.
Gaz
Forum Newbie
Posts: 2
Joined: Tue Dec 14, 2010 9:12 pm

Re: Text return with no line breaks

Post by Gaz »

Thank you both for your replies
it worked great :D
i now have a little more knowledge
its people like yourselves who share this knowledge make it more enjoyable for newbies like me who want to learn :)
Thanks again :)
Post Reply