troubleshooting Question

New BB Tag: [php] .. [/php]

Avatar of bahadirkocaoglu
bahadirkocaogluFlag for Turkey asked on
PHP
8 Comments1 Solution561 ViewsLast Modified:
Hi,

I need a custom bb tag.

Like:
[php]
<?php
echo 'test';
?>
[/php]

How can I do this?

Thanks.

I have currenty this code:
<?php
function parsemymessage($string) {
 
	// destroy slashes
	$string = stripslashes($string);
 
	// destroy html tags
	$string = strip_tags($string);
 
	// create smileys
	$string = str_replace(":)", "<img src=\"images/smileys/smiley.gif\" alt=\":)\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(":D", "<img src=\"images/smileys/cheesy.gif\" alt=\":D\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(";)", "<img src=\"images/smileys/wink.gif\" alt=\";)\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(";D", "<img src=\"images/smileys/grin.gif\" alt=\";D\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace("???", "<img src=\"images/smileys/huh.gif\" alt=\"???\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(":(", "<img src=\"images/smileys/sad.gif\" alt=\":(\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(":o", "<img src=\"images/smileys/shocked.gif\" alt=\":o\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(":`(", "<img src=\"images/smileys/cry.gif\" alt=\":`(\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(":*", "<img src=\"images/smileys/kiss.gif\" alt=\":*\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(":X", "<img src=\"images/smileys/lipsrsealed.gif\" alt=\":X\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
	$string = str_replace(":p", "<img src=\"images/smileys/tongue.gif\" alt=\":p\" width=\"18\" height=\"18\" border=\"0\" style=\"vertical-align: middle;\" />", $string);
 
	// bb codes
	$search = array(
			'/\[b\](.*?)\[\/b\]/is',
			'/\[i\](.*?)\[\/i\]/is',
			'/\[u\](.*?)\[\/u\]/is',
			'/\[s\](.*?)\[\/s\]/is',
			'/\[code\](.*?)\[\/code\]/is',
			'/\[quote\](.*?)\[\/quote\]/is',
			'/\[quote\=(.*?)\](.*?)\[\/quote\]/is',
			'/\[sub\](.*?)\[\/sub\]/is',
			'/\[sup\](.*?)\[\/sup\]/is',
			'/\[img\](.*?)\[\/img\]/is',
			'/\[url\](.*?)\[\/url\]/is',
			'/\[url\=(.*?)\](.*?)\[\/url\]/is'
	);
	$replace = array(
			'<strong>$1</strong>',
			'<em>$1</em>',
			'<u>$1</u>',
			'<s>$1</s>',
			'<div><b>Code:</b></div><div id="code">$1</div>',
			'<div><b>Quote:</b></div><div id="quote">$1</div>',
			'<div><b>Quote from: $1</b></div><div id="quote">$2</div>',
			'<sub>$1</sub>',
			'<sup>$1</sup>',
			'<img src="$1" />',
			'<a href="$1">$1</a>',
			'<a href="$1">$2</a>'
	);
	$string = preg_replace($search, $replace, $string);
 
	$search2 = array('(\[php\](.*?)\[/php\])se');
	$replace2 = array("''.highlight_string('$1', true).''");
	$string = preg_replace($search2, $replace2, $string);
 
	// \n or \r to <br>
	$string = nl2br($string);
 
	// destory spaces
	$string = trim($string);
 
	// return string
	return $string;
}
?>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros