Page 1 of 1

Problem text formatting in TEXTAREA

Posted: Mon Sep 22, 2003 5:35 am
by saeen
Hello thr
My name is Jd..and well today was my first day at job and i was assigned a task in PHP..Im not actually a PHP Programmer but have done the basics like DataBase connectivity...The problem i am facing is that first i had to save and retrieve data completly formatted like the carrige returns and stuff i did it but when i show it in a TEXTAREA it includes the <br/> n stuff i don wan it to show the actual tags...i used the htmlspecialchars as well but no use can any body temme wat to do???

$result = mysql_query("SELECT * from newsTable",$db);
while($myrow = mysql_fetch_array($result))
{
$myrow["comments"] = htmlspecialchars($myrow["comments"]);
$myrow["comments"] = nl2br($myrow["comments"]);
echo "Comment Start";
echo "<textarea rows=2 name=comments cols=20>".$myrow["comments"];
echo "</textarea>";
echo "<br>Comment End <br>";

}?>

Posted: Mon Sep 22, 2003 5:38 am
by JayBird
try this

Code: Select all

$myrow['comments'] = ereg_replace ("(<br />|<br/>)","", $myrow['comments']);
that will solve your , <br/> problems. But im not sure what other tags you have in there.

you may want to have a look at strip_tags() - http://se.php.net/manual/en/function.strip-tags.php

Could you post on example of what appears in the text box?

Mark

Posted: Mon Sep 22, 2003 5:48 am
by saeen
This is what appears in the textarea mark..this is field named COMMENTS in the database

PHP
<br /><br />
Java
<br /><br />
Servlets
<br /><br />
VB

Posted: Mon Sep 22, 2003 5:49 am
by JayBird
well, if you are only dealing with <br /> then the first example i gave would work for you.

Mark

Posted: Mon Sep 22, 2003 5:49 am
by saeen
thank u so much buddy that worked perfectly :)