Jump to content


bbcode problem


7 replies to this topic

#1 venomsnake

    Jedi In Training

  • Members
  • PipPip
  • 481 posts
  • Gender:Male

Posted 12 July 2006 - 10:42 PM

im having a problem with my bbcode, im adding a [ php ] [ /php ] tags in it along with highlight_string. it highlights fine, but i have on my forums htmlspecialchars so when it puts the info in the db it changes < to < etc, and when u view the info in the broser it switches back. but with the highlight_string, it doesnt change < back to <

here is my function for the highlight:

function highlight_php($matches) { 

	$php = "<strong>PHP Code:</strong><div style=\"margin:0px 10px; padding:5px; border:1px dotted #FFFFFF; width:90%\">"; 
	$php .= highlight_string($matches[0], true); 
	$php .= '</div>'; 
$php = str_replace("<", '<', $php);
	$php = str_replace("<br />", '', $php); 
	$php = preg_replace("@(\[php\]|\[/php\])@si", "", $php); 
	return $php; 
	
}

i tried to str_replace the < back to < but it wouldnt work.

also i have this in my bbcode function:

$post = preg_replace_callback("@\[php\](.*?)\[\/php\]@is", 'highlight_php', $post);

any help would be great.

thanks,
venomsnake

edit: i think its the htmlspecialchars, i tried $php .= highlight_string(htmlspecialchars('<?php ?>'), true); and it did the same thing

Edited by venomsnake, 12 July 2006 - 10:45 PM.


#2 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 13 July 2006 - 06:22 AM

try using htmlspecialchars_decode right after you pull it out of the databse and before you use it for anything

Edited by Avalanche, 13 July 2006 - 06:22 AM.


#3 venomsnake

    Jedi In Training

  • Members
  • PipPip
  • 481 posts
  • Gender:Male

Posted 13 July 2006 - 09:09 AM

i didnt know about that, never heard of the decode, thanks ill try it

edit: i put it like this and it works great, thanks:

$php .= highlight_string(htmlspecialchars_decode($matches[0]), true);

Edited by venomsnake, 13 July 2006 - 09:55 AM.


#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 July 2006 - 12:44 PM

What do you mean you try changing < into <, it's like saying i'm trying to change an apple into itself.
$php = str_replace("<", '<', $php);
That's pointless, you're chaging "<" into itself right there. You can also simplify the removal of the php BBcode tags by doing the following:
$php = preg_replace('@\[(/|)php\]@si', '', $php);
Now, if you're having problems getting &lt; to change to <, that would be a problem. As it stands right now, i'm completely lost on what the problem is.

Edited by rc69, 13 July 2006 - 12:50 PM.


#5 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 13 July 2006 - 12:47 PM

View Postvenomsnake, on Jul 13 2006, 03:09 PM, said:

edit: i put it like this and it works great, thanks:


Ummm, rc69, i think the problem is solved....;)

#6 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 13 July 2006 - 12:51 PM

lol Matt he is pointing out some stuff that he feels is wrong and pointless in that case just trying to make his code better.

#7 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 13 July 2006 - 12:54 PM

I give up...

Edit: Just say deadly's post... umm, matt was right, i missed the edit... But thanks for the excuse ;)

Edited by rc69, 13 July 2006 - 12:56 PM.


#8 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 13 July 2006 - 12:59 PM

lol rc69.

Just a side note, for anyone else who is trying venomsnake's soloution, you should note it's a PHP5 specific function.

You can however improvise and recreate the function yourself. Details are on php.net comments.

http://uk2.php.net/m...pecialchars.php

(scroll down).

Edited by .Matt, 13 July 2006 - 01:00 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users