Problem with textarea and echo statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rimpi1977
Forum Newbie
Posts: 5
Joined: Thu Oct 02, 2008 12:34 pm

Problem with textarea and echo statement

Post 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.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Problem with textarea and echo statement

Post by papa »

You can use echo nl2br($text);
rimpi1977
Forum Newbie
Posts: 5
Joined: Thu Oct 02, 2008 12:34 pm

Re: Problem with textarea and echo statement

Post 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...
rimpi1977
Forum Newbie
Posts: 5
Joined: Thu Oct 02, 2008 12:34 pm

Re: Problem with textarea and echo statement

Post by rimpi1977 »

Thanks it works......... :D
Post Reply