Forum Moderators: coopster
<form method="post" action="some.page">
<textarea id="my_text">
Some text
in your text
area.
</textarea>
<input type="submit" value="send">
</form>
// this on some.page
if ($_POST['submit']) { // form submitted
$raw_text = $_POST['my_text'];
$html_text = nl2br($_POST['my_text']);
echo "<p>Raw text:<br />$raw_text</p>";
echo "<p>Formatted Text:<br />$html_text</p>";
}
else {
// form not submitted
}
<?php
$form = <<<FORM
<form method="post" action="{$_SERVER['SCRIPT_NAME']}">
<textarea id="my_text" name="my_text">
Some text
in your text
area.
</textarea>
<input type="submit" value="send" name="Submit" />
</form>
FORM;
if (array_key_exists('Submit', $_POST)) {
$raw_text = $_POST['my_text'];
$html_text = nl2br($_POST['my_text']);
echo "<p>Raw text:<br />$raw_text</p>";
echo "<p>Formatted Text:<br />$html_text</p>";
}
else {
echo $form;
}
?>
All you need to do is use the nl2br() function on the retrieved information when you go to display it, for instance.
<?
$q = "SELECT my_text FROM table WHERE id='1';
$results = mysql_query($q);
$data = mysql_fetch_object($results);
echo nl2br($data->my_text);
?>
The issue you will run into when making the change before inserting it into the database is that if you allow updating later on, it will continue to add breaks every time thus ending up with more line breaks then you want.
However, since you asked:
An example would be something like this"
<?
$q = "INSERT INTO table (text) VALUES('".nl2br($_POST["my_text"])."') ";
?>
or
<?
$q = "UPDATE table SET text='".$_POST["my_text"]."'";
?>