Jump to content

Help removing <br> tags from output...


workbench

Recommended Posts

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:
-------------
test

test
-------------
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..


Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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..
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.