HTML tags in a php text var are getting displayed literally

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

HTML tags in a php text var are getting displayed literally

Post 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]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Maybe you're looking for nl2br()?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post by intellivision »

scottayy, thanks that did it.
Post Reply