John,

If I just echo $text on the webpage now, everything shows as it should.

HOWEVER, another problem I didn't even clue into until now. This form gets
emailed to a specified address and all I get in my email is one long line
with no line breaks. How do I fix this? I was reading a thread in a web
based group you were having with another person, but none of your
suggestions there worked.   

Suggestions....

Thanks again...

-----Original Message-----
From: John W. Holmes [mailto:[EMAIL PROTECTED] 
Sent: July 16, 2004 12:14 PM
To: PHP User
Cc: PHP
Subject: Re: [PHP] Need help with line breaks in a textarea form

PHP User wrote:
> Something came to mind as soon as I sent my last email, and it seems 
> to work. Not sure it will work in every circumstance but the few tests 
> I tried seemed ok. This is what I did. I added the two following lines to
my script.
> 
> $text=str_replace("\n","<br>",$text);
> $text=str_replace("<br />","",$text);

Okay... let's say you have $text that is text that was entered into a
textarea. To put it _back into_ a textare, you simply need to do this:

<textarea rows="5" cols="50"><?=htmlentities($text)?></textarea>

That's it. If you want to display $text to the user outside of a <textarea>,
then you do this:

echo nl2br(htmlentities($text));

If you want to insert $text into a database and magic_quotes_gpc is enabled,
you do this:

$query = "INSERT INTO yourtable (textcolumn) VALUES ('$text')";

If magic_quotes_gpc is not enabled (you can check with
get_magic_quotes_gpc(), btw), then you'd use this:

$text = addslashes($text);
$query = "INSERT INTO yourtable (textcolumn) VALUES ('$text')";

If you'd like to extract the winning lottery numbers from $text, you
simply...

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals - www.phparch.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to