Jump to content

Archived

This topic is now archived and is closed to further replies.

workbench

Help removing <br> tags from output...

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


Share this post


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

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
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  :)

Share this post


Link to post
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..

Share this post


Link to post
Share on other sites
Why do you want to remove the [code]<br>[/code] tags?

Ken

Share this post


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

Share this post


Link to post
Share on other sites

×

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.