You don't have to actually use <p> tags around every paragraph.... actually... you can use Divs and <br>s too.
You could use [man]nl2br[/man] upon submission. Then, when you retrieve it, that will be what it shows up as. If you want to have the <p> tags, you can do something like this:
<?php
$text = $_POST['textfield'];
$to_db = '';
$paras = explode("\n", $text);
foreach($paras as $para)
{
$to_db = '<p>'.$para.'</p>';
}
?>
Then just insert "$to_db" where you want the text to be....
It can also be ported to a function like:
function nl2p($input, $sql=FALSE)
{
$out = ''; // Empty the output variable
$paras = explode("\n", $input);
foreach($paras as $para)
{
$out .= '<p>'.$para.'</p>';
}
// If it's for SQL, let's escape it for security
if($sql){ $out = mysql_real_escape_string($out); }
return $out;
}
$query = "INSERT INTO faketable (name, email, comments) VALUES ('Someone', 'Blackhole@domain.com', '".nl2p($_POST['comments'], TRUE)."')";
~Brett