-
Insert line break?
I have a from that generates a html page what i have in the form is a few textarea boxes that the user fills in and then clicks submit. But the problem is it doesn't keep the line breaks "<br>" when it returns to the submitted form.
so on the html output form i have $input = $_POST['input'];
then the code for a table and <?php echo $input; ?> but instead of remembering the carrage returns it just warps the text.
How do i achieve this.
Thanks in Advance
-
hi,
You can use nl2br().
Here's a simple example:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>line breaks</title>
</head>
<body>
<?php
if (isset ($_POST['Submit']))
{
$input = $_POST['input'];
$input = nl2br ($input);
echo $input;
}
else
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="application/x-www-form-urlencoded" name="form1" target="_self" id="form1">
<textarea name="input" id="input"></textarea>
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
<?php
}
?>
</body>
</html>
Remember that there are some security measures that you should follow when receiving user input!
-
Hehe found out how to do it last night. But i want the text to html formatted. It gets outputted to a table in a email. So i had a script that inputs the html code for a image on the net now it doesnt work at all. Does nl2br() stop html properties?
Thanks for your help