Jump to content


Photo

Help removing <br> tags from output...


  • Please log in to reply
8 replies to this topic

#1 workbench

workbench
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 21 July 2006 - 05:18 AM

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:

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

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




#2 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 21 July 2006 - 05:50 AM

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

#3 workbench

workbench
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 21 July 2006 - 06:35 AM

does that help?

#4 chrisprse

chrisprse
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • LocationUnited Kingdom

Posted 21 July 2006 - 09:24 AM

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:
<br />

hth

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 21 July 2006 - 09:40 AM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 chrisprse

chrisprse
  • Members
  • PipPipPip
  • Advanced Member
  • 39 posts
  • LocationUnited Kingdom

Posted 21 July 2006 - 10:11 AM

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

#7 workbench

workbench
  • Members
  • PipPip
  • Member
  • 14 posts

Posted 21 July 2006 - 11:19 AM

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

#8 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 July 2006 - 12:15 PM

Why do you want to remove the
<br>
tags?

Ken

#9 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 July 2006 - 02:47 PM

With the code:
$row_f->f_matt = nl2br(preg_replace("<br />","",$row_f->f_matt));
your are removing the br tags (with preg_replace), then your are putting them back in again (with nl2br)! Seems pointless to me.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users