workbench Posted July 21, 2006 Share Posted July 21, 2006 I'm pretty new to php so please be forgiving...I've created a forum with a text field. Users can input text and when they hit "return" just like I'm doing now...they see the returns in there text box(like I see in this one). However once the post is made the line breaks are gone and instead output <br> tags. For example, If I typed:-------------testtest-------------The output would be:-------------------test <br> <br> test-------------------I've managed to get rid of the "br" and insert the correct line break using the following code:[code]<tr><td class="body"><font color="#666666" size="2"> <? $row_f->f_matt = nl2br(preg_replace("<br>","",$row_f->f_matt)); echo stripslashes($row_f->f_matt); if($row_f->edited!=0) echo "</font><br><br><i>Post edited by moderator at ".date("j-m-YH:i:s",$row_f->edited)."</i>"; ?></td></tr>[/code]However this does not remove the carrots. So the output from above is now:---------test<><>test---------Anyone know how to get rid of the <>'s? This is driving me nuts..Any help ould be appreciated.. Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/ Share on other sites More sharing options...
akitchin Posted July 21, 2006 Share Posted July 21, 2006 it would help if you used code tags to surround your output (at the start of the message), as otherwise we can't see the actual original output (before you run your stuff on it). Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61524 Share on other sites More sharing options...
workbench Posted July 21, 2006 Author Share Posted July 21, 2006 does that help? Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61534 Share on other sites More sharing options...
chrisprse Posted July 21, 2006 Share Posted July 21, 2006 Hi,nl2br() should help you.For example, if you have a text area, when the form is submitted you will have something like:$_POST['textarea'];Simply use: echo nl2br($_POST['textarea']);This will change all new lines in the text area to line breaks: [CODE]<br />[/CODE]hth Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61557 Share on other sites More sharing options...
Barand Posted July 21, 2006 Share Posted July 21, 2006 Bad idea Chisprse.Store the text in the db with original newline chars. Use nl2br() only when you output to the page.That way, if you subsequently want to read it into a text area for editing, you don't get the BR/ in the text to be edited and you still get the original format. Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61561 Share on other sites More sharing options...
chrisprse Posted July 21, 2006 Share Posted July 21, 2006 Hi, that's right, I only gave a quick example above as it seems as though he didn't realize this function was available. Your right in saying store the contents with new line characters :) Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61573 Share on other sites More sharing options...
workbench Posted July 21, 2006 Author Share Posted July 21, 2006 I actually am using nl2br() to create the line breaks, and then preg_replace to remove the <br>. $row_f->f_matt = nl2br(preg_replace("<br>","",$row_f->f_matt));but the preg_replace command I'm using just removes the br and leaves the <> in the output.I'm stumped.. Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61592 Share on other sites More sharing options...
kenrbnsn Posted July 21, 2006 Share Posted July 21, 2006 Why do you want to remove the [code]<br>[/code] tags?Ken Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61603 Share on other sites More sharing options...
wildteen88 Posted July 21, 2006 Share Posted July 21, 2006 With the code:[code]$row_f->f_matt = nl2br(preg_replace("<br />","",$row_f->f_matt));[/code]your are removing the br tags (with preg_replace), then your are putting them back in again (with nl2br)! Seems pointless to me. Quote Link to comment https://forums.phpfreaks.com/topic/15222-help-removing-tags-from-output/#findComment-61663 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.