Jump to content

please help about bbcode


teomanersan

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


[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);
[/code]

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

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

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
Link to comment
Share on other sites

Hmm.. Are you trying to make bbcode ?
Try this function I'm using:
[code]<?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;
}

?>[/code]

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:
[code]<?php
include('functions');
$text = "[bkz]test[/bkz]";
echo bbcode($text);
?>[/code]

Enjoy :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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