Jump to content


Photo

Keeping paragraphs etc.


  • Please log in to reply
2 replies to this topic

#1 jcstanley

jcstanley
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 16 October 2006 - 05:56 PM

Hi
I am currently copying data into a database from an existing page on my site.

When the text is entered into a text area on a form it is paragraphed.  But when viewed on the page wich retrieves the data from the database it is just one continuous chunk of text.

Is there any way of keeping the paragraphs etc? (A similar format to entering a post on this site would be ideal)

Thanks

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 16 October 2006 - 06:01 PM

What are you using to view the data in the database?

When displaying the data back to a browser, the browser does not interpret the newline character. To be able to show the text correctly use the nl2br() function.

Example:
<?php
$text =  "this text has \nnewline\n characters in it";
echo nl2br($text);
?>

Ken

#3 jcstanley

jcstanley
  • Members
  • PipPipPip
  • Advanced Member
  • 74 posts

Posted 16 October 2006 - 06:18 PM

Cheers Ken

That works perfectly!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users