473,573 Members | 2,930 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to handle line breaks when storing textarea entry in a database?

I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags
in HTML. How can I do that. So far, although it occurs naturally when
I save the contents to a file, it doesn't break up the paragraphs
properly when I save it to my database.

Thanks!

Jonathan
http://thewebdevelopment.com
Jul 20 '05 #1
6 63012
"Jonathan" wrote:
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally when I save the contents to a file, it doesn’t break up the
paragraphs
properly when I save it to my database.

Thanks!

Jonathan
http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-handle...ict131179.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438213
Jul 20 '05 #2

"Jonathan" <th************ ***@yahoo.com> wrote in message
news:67******** *************** ***@posting.goo gle.com...
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags
in HTML. How can I do that. So far, although it occurs naturally when
I save the contents to a file, it doesn't break up the paragraphs
properly when I save it to my database.

You need to replace your \r\n with <p />
and your \n with <br />

php code sample (handles dos and *nix text):

$string = ereg_replace("( \r\n\r\n|\n\n|\ r\r)", "<p />", $_POST['testtext']);

^^^^^^^^^^^^^

Text from query

$string = stripcslashes(e reg_replace("(\ r\n|\n|\r)", "<br />", $string));

print $string;
Jul 20 '05 #3
"Jonathan" wrote:
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally when I save the contents to a file, it doesn’t break up the
paragraphs
properly when I save it to my database.

Thanks!

Jonathan
http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/mySQL-handle...ict131179.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=438213
Jul 20 '05 #4

"Jonathan" <th************ ***@yahoo.com> wrote in message
news:67******** *************** ***@posting.goo gle.com...
I want to save textarea contents to a mysql database with the
paragraph breaks intact without having to type paragraph or break tags
in HTML. How can I do that. So far, although it occurs naturally when
I save the contents to a file, it doesn't break up the paragraphs
properly when I save it to my database.

You need to replace your \r\n with <p />
and your \n with <br />

php code sample (handles dos and *nix text):

$string = ereg_replace("( \r\n\r\n|\n\n|\ r\r)", "<p />", $_POST['testtext']);

^^^^^^^^^^^^^

Text from query

$string = stripcslashes(e reg_replace("(\ r\n|\n|\r)", "<br />", $string));

print $string;
Jul 20 '05 #5
steve wrote:
"Jonathan" wrote:
> I want to save textarea contents to a mysql database with the
> paragraph breaks intact without having to type paragraph or break

tags
> in HTML. How can I do that. So far, although it occurs naturally

when
> I save the contents to a file, it doesn’t break up the
> paragraphs
> properly when I save it to my database.
>
> Thanks!
>
> Jonathan
> http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

I would like to suggest a small correction:

A 'paragraph break' is actually CR/LF. A textarea will break lines using
wordwrap. (To some people a paragraph break is known as a 'hard break':
its hard-coded, whereas a wordwrap is a 'soft break': software
calculates it.) A wordwrap doesn't actually use any symbol wthin the
stored text, since the position of the line breaks will alter depending
on the media in which the text is displayed.

HTML also uses wordwrap, but it ignores CR/LF. In its place you can use
either a <BR> for linebreak or <p> for paragraphs. If you have a block
of text which uses CR/LFs that you wish to display in HTML, then you'll
need to substitute <br> for each of the CR/LFs. (in PHP there is a
function nl2br() that does this.)

History: CR/LF goes back to the days of early printers where the codes
replicated the actions of a typewriter. CR (carriage return) returned
the carriage to the start of a new line. LF (line feed) advanced to the
next line. The lever at the left end of a typewriter combined moving
the carriage and advancing the line. Typists used to apply a CR/LF at
the end of every line and an extra CR/LF between paragraphs. As electric
typewriters came into use they would automatically apply the CR/LF when
the end of the line was reached.

Now with wordprocessing and wordwrap, the CR/LF at the end of each line
is no longer neccessary.

Any corrections/improvements to this explanation would be greatfully
received.

Mike
Jul 20 '05 #6
steve wrote:
"Jonathan" wrote:
> I want to save textarea contents to a mysql database with the
> paragraph breaks intact without having to type paragraph or break

tags
> in HTML. How can I do that. So far, although it occurs naturally

when
> I save the contents to a file, it doesn’t break up the
> paragraphs
> properly when I save it to my database.
>
> Thanks!
>
> Jonathan
> http://thewebdevelopment.com


Jonathan, textarea uses cr\lf to break lines. That is how it would
be saved into db, if your program does no extra translations. Upon
display on html page, cr\lf could then be replaced by html break
tags.

I don’t know of paragraph breaks. I believe that is simply double
cr\lf’s.

I would like to suggest a small correction:

A 'paragraph break' is actually CR/LF. A textarea will break lines using
wordwrap. (To some people a paragraph break is known as a 'hard break':
its hard-coded, whereas a wordwrap is a 'soft break': software
calculates it.) A wordwrap doesn't actually use any symbol wthin the
stored text, since the position of the line breaks will alter depending
on the media in which the text is displayed.

HTML also uses wordwrap, but it ignores CR/LF. In its place you can use
either a <BR> for linebreak or <p> for paragraphs. If you have a block
of text which uses CR/LFs that you wish to display in HTML, then you'll
need to substitute <br> for each of the CR/LFs. (in PHP there is a
function nl2br() that does this.)

History: CR/LF goes back to the days of early printers where the codes
replicated the actions of a typewriter. CR (carriage return) returned
the carriage to the start of a new line. LF (line feed) advanced to the
next line. The lever at the left end of a typewriter combined moving
the carriage and advancing the line. Typists used to apply a CR/LF at
the end of every line and an extra CR/LF between paragraphs. As electric
typewriters came into use they would automatically apply the CR/LF when
the end of the line was reached.

Now with wordprocessing and wordwrap, the CR/LF at the end of each line
is no longer neccessary.

Any corrections/improvements to this explanation would be greatfully
received.

Mike
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1611
by: Christopher Glaeser | last post by:
Consider the code: $arrText = file ("http://www.site.com/page.htm"); for ($i=0; $i<count($arrText); i++) { echo("$arrText\n"); } (I did not test the snippet for errors) The line breaks appear to be different from the original .htm file. Why?
0
710
by: Jonathan | last post by:
I want to save textarea contents to a mysql database with the paragraph breaks intact without having to type paragraph or break tags in HTML. How can I do that. So far, although it occurs naturally when I save the contents to a file, it doesn't break up the paragraphs properly when I save it to my database. Thanks! Jonathan...
4
22743
by: intl04 | last post by:
I have a memo field that is included in some Access reports I created. Is there some way for the memo field to display nicely formatted text, with line breaks between paragraphs? Or is it necessary to export the report? I tried exporting a report by using the .rtf rich-text format (the plain-text format was the only other word-processing...
0
1525
by: Peter Rilling | last post by:
Although an ADODB question, I am using C#, so here I go. I am trying to use the ADODB Stream object to extract content from a body part of an MHTML formatted document. I can save the raw information and see what it looks like. Now, when I go to do some extra processing, I need to load the contents a body part using the code below. This is...
5
16831
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the line breaks with <br /> tags ( using the php function nl2br() ), and <br /> tags showed up in the textarea.
8
2064
by: Juan Puebla | last post by:
Hi, I have an sql database with some text (nvarchar) fields. The problem is that if I get those fields with a datareader (dr.getstring(0)) an then I save text in a txt file I loose all the line breaks. If I open database Studio Management I see fields like this: Això és una proba pel texte sql. Els canvis de línia no es controlen bé
14
17955
by: ghostwalker | last post by:
Hi I have an HTML form with a textarea on it. When submitted (using 'get' not 'post') this forms action php file simply does this to retrieve the values: $message = $_GET; Now it all works fine but I get the string in one long string with no '\n' where the user pressed 'return key'
1
6060
by: Arielle | last post by:
Trying to migrate from ASP classic to ColdFusion and was wondering how to handle this. A form has a text area that submits to a database and stores a memo that can later be viewed. How can I display the field on the page while maintaining all the style information i.e. line breaks and spacing entered into it? Of course the <pre> tag works but...
4
10622
by: Steve Marson | last post by:
I am using a simple form in modx CMS and I need the textarea to retain the line breaks. I'd prefer a javascript solution if possible. This is because the textarea will be used to order food and the client doesn't want to receive a single line of text. eg, this entry: 1 can coke 3 beef sandwiches 1 cake
0
7684
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6400
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5579
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3729
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3729
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2191
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1295
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1035
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.