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