p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: formatting text


Message #1 by gareth.mccullough@v... on Wed, 27 Feb 2002 15:26:36
Silly question but what is the easiest and most efficient way to format 

text in a database.  I want to submit from a textarea to a database and 

display the text somewhere else, but if i were to enter a couple of 

paragraphs within the textarea and submit it to a database.  When i 

displayed what was in the database, it comes out as 1 long string.  So how 

can i format the text so that what i entered in is what i will get out??



Cheers in advance
Message #2 by "Hermawan Haryanto" <hermawan@h...> on Wed, 27 Feb 2002 22:34:44 +0700
When u print it out, use nl2br language construction.

Like this :

$str = nl2br($str);

print $str;



Thanks



Hermawan Haryanto

hermawan@h...

----- Original Message -----

From: <gareth.mccullough@v...>

To: "beginning php" <beginning_php@p...>

Sent: Wednesday, February 27, 2002 3:26 PM

Subject: [beginning_php] formatting text





> Silly question but what is the easiest and most efficient way to format

> text in a database.  I want to submit from a textarea to a database and

> display the text somewhere else, but if i were to enter a couple of

> paragraphs within the textarea and submit it to a database.  When i

> displayed what was in the database, it comes out as 1 long string.  So how

> can i format the text so that what i entered in is what i will get out??

>

> Cheers in advance




$subst('Email.Unsub').

>



Message #3 by David Keyes <dave@s...> on Wed, 27 Feb 2002 08:50:45 -0800
gareth.mccullough@v... wrote:



> Silly question but what is the easiest and most efficient way to format

> text in a database.  I want to submit from a textarea to a database and

> display the text somewhere else, but if i were to enter a couple of

> paragraphs within the textarea and submit it to a database.  When i

> displayed what was in the database, it comes out as 1 long string.  So how

> can i format the text so that what i entered in is what i will get out??

>

> Cheers in advance






I think it might be the browser that fails to format the text. I used a BLOB in

the database and had that problem using a netscape (4.7) browser but it worked ok

on the Opera browser. I guess there may be a way to add hard returns using an

escape code sequence.







Message #4 by "Lawrence" <lkrubner@g...> on Wed, 27 Feb 2002 12:02:42 -0500
From: <gareth.mccullough@v...>

> Silly question but what is the easiest and most efficient way to format

> text in a database.  I want to submit from a textarea to a database and

> display the text somewhere else, but if i were to enter a couple of

> paragraphs within the textarea and submit it to a database.



I got your email and then the very next email I got was from PHP Classes, which might be worth a

look, as this one is on textareas:



-----------------------------------------------------

A new class was added to "PHP Classes" repository.

Name: TextArea

Author: Mark van Oort <markie@g...>

Description:

Show a textarea with text from database you can change.

URL: http://www.phpclasses.org/browse.html/package/454.html













Message #5 by Jacob Cohen <cohen@r...> on Wed, 27 Feb 2002 09:12:40 -0800
On 2/27/2002,  <dave@s...> wrote:

>> Silly question but what is the easiest and most efficient way to format

>> text in a database.  I want to submit from a textarea to a database and

>> display the text somewhere else, but if i were to enter a couple of

>> paragraphs within the textarea and submit it to a database.  When i

>> displayed what was in the database, it comes out as 1 long string.  So how

>> can i format the text so that what i entered in is what i will get out??



> I think it might be the browser that fails to format the text. I used a BLOB in

> the database and had that problem using a netscape (4.7) browser but it worked ok

> on the Opera browser. I guess there may be a way to add hard returns using an

> escape code sequence.



The problem is rather, I believe, that the newlines are not being

displayed by the browser, which is perfectly normal behavior. In HTML

processing, any run of consecutive whitespace characters (including

newlines) is reduced to a single space.



OP: Hermawan Haryanto already suggested the solution to this problem,

and I believe Nikolai Devereaux answered this same question about a

month ago. This goes to show it might be advantageous to search list

archives before asking a FAQ :)



In fact, in about 11 seconds, I found the thread using google:

http://p2p.wrox.com/archive/beginning_php/2002-01/17.asp



-- 

Regards,

Jake                            mailto:cohen@r...




  Return to Index