Jump to content


Photo

please help about bbcode


  • Please log in to reply
4 replies to this topic

#1 teomanersan

teomanersan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 June 2006 - 04:03 AM

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..

[bkz][bkz]test*[*bkz][/bkz]

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


#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 22 June 2006 - 08:40 AM

Hmm.. Are you trying to make bbcode ?
Try this function I'm using:
<?php

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.

Usage:
<?php
include('functions');
$text = "[bkz]test[/bkz]";
echo bbcode($text);
?>

Enjoy :)

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 teomanersan

teomanersan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 22 June 2006 - 09:53 AM

no i`m not trying to make bbcode.. i`m trying to convert bbcode into html equivalent..

thx :)

#4 teomanersan

teomanersan
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 24 June 2006 - 03:40 PM

c`mon guys ? is it impossible ?

#5 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 25 June 2006 - 03:47 AM

My reply doesn't helped ?
I thought you want to have bbcode that convert to html when you typed
[bkz]blah...[/bkz]
and
[bkz]blah...[*bkz]

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users