Page 1 of 1

HTML tags in a php text var are getting displayed literally

Posted: Mon Oct 29, 2007 7:40 pm
by intellivision
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

preg_replace( '(<p>|</p>)', '', $row->post_text);
That is taking post_text and removing the paragraph tags, obviously. Reson: the tags are displayed literally as
<p> and </p> when the result is spit back out and displayed in my forum.

How can I have nice paragraphs in the text that's spit back out without having the literal paragraph tags?

I tried

Code: Select all

preg_replace( '(<p>|</p>)', '\n', $row->post_text);
but that spits out a literal "\n" between paragraphs. Ack.

I'm getting literalled to death here.

Here's the whole bit

Code: Select all

function bb_quote_message() {
	global $bbdb, $topic;
	$post_id = (int)$_GET['quote']; 
	$the_author = $_GET['author'];
	$the_author = str_replace('!~', ' ', $the_author);
	if ($post_id) {
		$row = $bbdb->get_row("SELECT * FROM $bbdb->posts WHERE post_id={$post_id} AND topic_id={$topic->topic_id} AND post_status=0");
		$row->post_text = rtrim(preg_replace( '(<p>|</p>)', '', $row->post_text));
		if ($row) echo ($the_author.' said:<br />'.htmlentities('<blockquote>'.$row->post_text.'</blockquote>', ENT_COMPAT, 'UTF-8')."\n");
	}
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Oct 30, 2007 3:25 am
by s.dot
Maybe you're looking for nl2br()?

Posted: Tue Oct 30, 2007 1:11 pm
by intellivision
scottayy, thanks that did it.