LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


Hello.

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 LQ.org box i am typing in at the moment seems to have this ability.

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

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

Rep: Reputation: 31
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:

Code:
$sFormattedString = str_replace("\n", "<br>", $sOriginalString);
 
Old 11-24-2004, 05:48 PM   #3
sigsegv
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.
 
  


Reply


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 12:07 PM.

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