Problem text formatting in TEXTAREA

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
saeen
Forum Newbie
Posts: 24
Joined: Mon Sep 22, 2003 5:35 am
Contact:

Problem text formatting in TEXTAREA

Post 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>";

}?>
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
saeen
Forum Newbie
Posts: 24
Joined: Mon Sep 22, 2003 5:35 am
Contact:

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

well, if you are only dealing with <br /> then the first example i gave would work for you.

Mark
saeen
Forum Newbie
Posts: 24
Joined: Mon Sep 22, 2003 5:35 am
Contact:

Post by saeen »

thank u so much buddy that worked perfectly :)
Post Reply