irkevin Posted September 8, 2008 Share Posted September 8, 2008 Hi all, I have one question, I have a textarea and i'm using php to insert the data in mysql. I'm using nl2br() to add linebreaks. The problem is, when i output the tag in the textarea again, it shows up with the <br /> tag, how do i hide them? I've tried this while($myarray = mysql_fetch_array($result)){ $title = $myarray['title']; $contents = $myarray['contents']; $contents = str_replace("<br />", "\n", $contents); } But with no luck. Can someone help me? Quote Link to comment https://forums.phpfreaks.com/topic/123254-solved-how-to-hide-ltbr-gt-tag-in-textarea/ Share on other sites More sharing options...
elmas156 Posted September 8, 2008 Share Posted September 8, 2008 Have you tried putting a forward slash in front of the quotation marks? Like this: $contents = str_replace(\"<br />\", "\n", $contents); Quote Link to comment https://forums.phpfreaks.com/topic/123254-solved-how-to-hide-ltbr-gt-tag-in-textarea/#findComment-636530 Share on other sites More sharing options...
JonnoTheDev Posted September 8, 2008 Share Posted September 8, 2008 Dont use the nl2br() function when placing the text back into the text area. Only use this function when displaying the text on the screen within the HTML. The text should remain formatted in the text area. Quote Link to comment https://forums.phpfreaks.com/topic/123254-solved-how-to-hide-ltbr-gt-tag-in-textarea/#findComment-636532 Share on other sites More sharing options...
irkevin Posted September 8, 2008 Author Share Posted September 8, 2008 I'm not using the nl2br() when outputting back I tried your solution elmas156 , but with no luck Quote Link to comment https://forums.phpfreaks.com/topic/123254-solved-how-to-hide-ltbr-gt-tag-in-textarea/#findComment-636534 Share on other sites More sharing options...
JonnoTheDev Posted September 8, 2008 Share Posted September 8, 2008 Then you must be saving the text into the database using nl2br(). The BR tags do not need to be stored in the DB. Line breaks will be saved as \r\n in your DB automatically. Use the nl2br() function only when formatting inside HTML. Quote Link to comment https://forums.phpfreaks.com/topic/123254-solved-how-to-hide-ltbr-gt-tag-in-textarea/#findComment-636536 Share on other sites More sharing options...
irkevin Posted September 8, 2008 Author Share Posted September 8, 2008 i think i've figured it out im just using $contents = str_replace("<br />","",$contents); and it seems to be working fine. I'll make another test to see! Quote Link to comment https://forums.phpfreaks.com/topic/123254-solved-how-to-hide-ltbr-gt-tag-in-textarea/#findComment-636538 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.