Page 1 of 1

Text return with no line breaks

Posted: Tue Dec 14, 2010 9:27 pm
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:

Re: Text return with no line breaks

Posted: Wed Dec 15, 2010 10:23 am
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']);
  ...
}

Re: Text return with no line breaks

Posted: Wed Dec 15, 2010 10:33 am
by superdezign
Also, if you are giving raw data, you may want to consider using the <pre> tag.

Re: Text return with no line breaks

Posted: Thu Dec 16, 2010 8:39 am
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 :)