Jump to content


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


please help about bbcode

Recommended Posts

hi guys..

i am using two bbcode tags for linking inside my site which are [bkz] [/bkz] and [bkz] [*bkz]

for this, i'm using this code..

$comment = preg_replace("#\[bkz](.*?)\[/bkz\]#ise", "'<a title=\"(bkz.\\1)\" href=\"ajaxcomsayfa.php?ara='.urlencode('\\1').'\">\\1</a>'",$comment);
$comment = preg_replace("#\[bkz](.*?)\[\*bkz\]#ise", "'<a title=\"(bkz.\\1)\" href=\"ajaxcomsayfa.php?ara='.urlencode('\\1').'\" >*</a>'",$comment);

works fine.. but now i want to convert bbcode to html.. so i used preg_replace again..

$comment = preg_replace("#(<a title=(.+?) href=(.+?) >(.+?)</a>)#is","[bkz]\\1[/bkz]",$comment);
$comment = preg_replace("#(<a title=(.+?) href=(.+?) >\*</a>)#is","[bkz]\\1[/*bkz]",$comment);

now the problem starts ... it gives the output like this IF i use $comment = striptags($comment) and both tags were used..


if only one tag is used, nothing shows up :((

else it gives tags plus the html codes and drives me NUTS !!!!

please if anyone know how to get rid of this problem, let me know !!!

basicly what i want is:

<a title="(bkz.test)" href="ajaxcomsayfa.php?ara=test">test</a> TO -> [bkz]test[/bkz]

<a title="(bkz.test)" href="ajaxcomsayfa.php?ara=test">*</a> TO -> [bkz]test[*bkz]

thanx for your time and any help is HIGHLY appericiated..

good coding

Share this post

Link to post
Share on other sites
Hmm.. Are you trying to make bbcode ?
Try this function I'm using:

function bbcode($text)
$pattern[] = '//';
$replace[] = '';

$pattern[] = '/\n/';
$replace[] = '<br>';

$pattern[] = '/\[b\](.*?)\[\/b\]/';
$replace[] = '<span style="font-weight:bold">$1</span>';

$pattern[] = '/\[i\](.*?)\[\/i\]/';
$replace[] = '<span style="font-style:italic">$1</span>';

$pattern[] = '/\[u\](.*?)\[\/u\]/';
$replace[] = '<span style="text-decoration:underline">$1</span>';

$pattern[] = '/\[color=(.*?)\](.*?)\[\/color\]/';
$replace[] = '<span style="color: $1">$2</span>';

$pattern[] = '/\[url=(.*?)\](.*?)\[\/url\]/';
$replace[] = '<a href="$1">$2</a>';

$pattern[] = '/\[url\](.*?)\[\/url\]/';
$replace[] = '<a href="$1">$1</a>';

$pattern[] = '/\[img\](.*?)\[\/img\]/';
$replace[] = '<img src="$1">';

$pattern[] = '/\[b\](.*?)\[\/b\]/';
$replace[] = '<b>$1</b>';

$pattern[] = '/\[bkz\](.*?)\[\/bkz\]/';
$replace[] = '<a title="(bkz.$1)" href="ajaxcomsayfa.php?ara=test">$1</a>';

$pattern[] = '/\[bkz\](.*?)\[\*bkz\]/';
$replace[] = '<a title="(bkz.$1)" href="ajaxcomsayfa.php?ara=test">$1</a>';

$text = preg_replace($pattern, $replace, $text);
return $text;


P.S : I have added I have added what you want at the last 2 bbcode, save this file as functions.php or anything.

$text = "[bkz]test[/bkz]";
echo bbcode($text);

Enjoy :)

Share this post

Link to post
Share on other sites
My reply doesn't helped ?
I thought you want to have bbcode that convert to html when you typed

Share this post

Link to post
Share on other sites


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.