Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 21st, 2004, 04:09 PM
Authorized User
 
Join Date: Aug 2003
Location: Coeur d\'Alene, ID, USA.
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default line breaks in MySQL field?

Can a MySQL field contain text that has line breaks?

__________________
An overworked Web Developer who\'s expected to know everything yet given time to study nothing.
Reply With Quote
  #2 (permalink)  
Old May 21st, 2004, 04:22 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Yes.

Do you need to know how to reproduce those line breaks with HTML? Assuming you do.. look at nl2br().

http://www.php.net/nl2br

When a user enters text into a <textarea> field, for example, a newline character is inserted at every line break. It's backslash followed by the letter n or "\n". These are invisible for the most part and HTML doesn't reproduce them without something like the <pre> tag or white-space: pre; using CSS. nl2br inserts an HTML line break where ever this character is present in the text.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
  #3 (permalink)  
Old May 21st, 2004, 05:19 PM
Authorized User
 
Join Date: Aug 2003
Location: Coeur d\'Alene, ID, USA.
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Tachyon
Default

Thanks for the great response. I'm a newbie so I really appreciate this stuff.

So, if a <textarea> feeds into a MySQL field, and then I print the database info to a file, the line breaks will be preserved?

The reason I'm asking about this is I'm working on a contact database. When the office staff want to do a postal mailing, they'll run a program that queries the database and creates a text file. They'll then burn the text file to a CD and send it to the mailing service to print onto envelopes.

Reply With Quote
  #4 (permalink)  
Old May 21st, 2004, 06:03 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:Originally posted by Tachyon

So, if a <textarea> feeds into a MySQL field, and then I print the database info to a file, the line breaks will be preserved?
Yes. The ideal field type to contain the data would be text, mediumtext, longtext, whichever is suitable given the necessary constraints on size. But the newline character is passed as part of the data and it won't get removed unless you run an algorithm to remove it specifically. When you write the data to a plain text file and open it with a plain text viewer you'll see the linebreaks where they occured in the <textarea> field. In a browser, when viewed in HTML it won't appear that way unless you use a function like nl2br to insert HTML line breaks or the other methods I mentioned, but if you view the source of the file you'll see the line breaks in the source where they occured in the <textarea> field.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
line breaks mister_mister XSLT 14 March 17th, 2008 12:55 PM
How to do line breaks! Apocolypse2005 Beginning VB 6 2 December 11th, 2006 03:20 PM
problems with line breaks sanchezal XSLT 7 July 30th, 2003 03:09 AM



All times are GMT -4. The time now is 10:31 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.