Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-23-2004, 08:08 PM   #1
Registered: Jan 2004
Location: new zealand
Distribution: Mandrake,Slackware
Posts: 165

Rep: Reputation: 30
PHP+SQL : formatting text for presentation in a blob


I have some PHP and SQL pages where users can compose messages and save them.

The users type in their text into a html textarea and then PHP saves the string into a longblob type field in the SQL database.

My problem is this means all formatting like line breaks and spaces are lost.

How can i have the message understand where line breaks are and so forth without having the user type in the html code them self?

I know it must be possible since the box i am typing in at the moment seems to have this ability.

do i need to use a client-side scripting language?

Old 11-24-2004, 08:20 AM   #2
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
I'm guessing that your problem isn't so much that your data is being saved w/o the line breaks as it is that when displayed the HTML does what HTML does and ignores those line breaks and extra whitespace when displayed.

You can fix this by replacing the line breaks with a <br> using the str_replace method. Either before storing the data in the database, or after you read the data from the database and before you display it...

Something like:

$sFormattedString = str_replace("\n", "<br>", $sOriginalString);
Old 11-24-2004, 05:48 PM   #3
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 46
And don't forget to use mysql_real_escape_string()

SQL injection is a bad thing.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I keep the formatting out of a text document? joshknape Linux - Software 12 09-09-2005 07:32 PM
Wierd Linux text formatting figgypower Linux - Software 1 08-05-2004 10:34 PM
sql text client pao Linux - Newbie 2 07-28-2004 07:50 AM
Best language for automated text formatting darin3200 Programming 5 07-05-2004 10:18 PM
TCL/TK Formatting text liguorir Linux - Software 0 05-02-2004 09:42 AM

All times are GMT -5. The time now is 04:15 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration