Page 1 of 1
Problem with textarea and echo statement
Posted: Thu Oct 02, 2008 12:45 pm
by rimpi1977
Hello,
I am a new user and php learner.
I wanna know that if I add a textarea in a form and when I recall this text with echo statement It appears without formatting.
like---If I enter some text this way:-
----------------------------
Hello,
I am Rahul and I wanna know something.
can you tell me
----------------------------
Now when I use echo state ment it appears like
Hello,I am Rahul and I wanna know something.can you tell me
Please help me.
Re: Problem with textarea and echo statement
Posted: Thu Oct 02, 2008 12:53 pm
by papa
You can use echo nl2br($text);
Re: Problem with textarea and echo statement
Posted: Thu Oct 02, 2008 12:57 pm
by rimpi1977
actually I use-
<!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>Untitled Document</title>
</head>
<body>
<form action="test2.php" method="post">
<textarea name="mes" cols="20" rows="10"></textarea>
<input name="send" type="submit" value="send" />
</form>
</body>
</html>
and when I echo this I use
<!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>Untitled Document</title>
</head>
<body>
<?php
if (isset($_POST['mes'])) {
$mes = $_POST['mes'];
}
if (isset($_GET['mes'])) {
$mes = $_GET['mes'];
}
if(!$mes)
{
?>
<form method="post">
<textarea name="mes" cols=10 rows=10></textarea>
<input type="submit" value="send">
</form>
<?php
}
else
{
$mes= str_replace('\n','',$mes);
echo"$mes";
}
?>
</body>
NOW PLEASE ADD YOUR CODE TO HELP ME FRIENDS...
Re: Problem with textarea and echo statement
Posted: Thu Oct 02, 2008 1:25 pm
by rimpi1977
Thanks it works.........
