Jump to content

BBCode [code] Tag


RobertP

Recommended Posts

How can i disable bbcode inside the code tags?.

 

for example

 

[ code ]test [ b ]bold[/ b ] test[/ code ]

 

the bold is [ b ]bold[/ b ] instead of bold

 

i am not sure how to explain this more clearly.

 

$string = '[b]this[/b] is [b]a[/b] very [b]boldy[/b] message.
[url=http://www.google.ca/]click here[/url] or this [url]http://www.google.ca/[/url]';

$bbc = array(
'b'=>array(
	'expression'=>'/\[b\](.*?)\[\/b\]/',
	'result'=>'<span style=font-weight:bold;>\\1</span>',
),
'url2'=>array(
	'name'=>'Link',
	'display_in_commands'=>false,
	'expression'=>'/\[url=(.*?)\](.*?)\[\/url\]/',
	'result'=>'<a href="\\1" target="_blank">\\2</a>',
),
'url'=>array(
	'name'=>'Link',
	'display_in_commands'=>true,
	'expression'=>'/\[url\](.*?)\[\/url\]/',
	'result'=>'<a href="\\1" target="_blank">\\1</a>',
)
'code'=>array(
	'name'=>'Code',
	'display_in_commands'=>true,
	'expression'=>'/\[code\](.*?)\[\/code\]/',
	'result'=>'<div class="bbc-code-tag">\\1</div>',
),
);

$expressions = $results = array();
foreach($bbc as $tag => $code){
$expressions[] = $code['expression'];
$results[] = $code['result'];
}
$string = preg_replace($expressions,$results,$string);
$string = str_replace("\r\n",'<br />',$string);//convert line breaks.

echo $string;

Link to comment
https://forums.phpfreaks.com/topic/258817-bbcode-code-tag/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.