Topic: Custom UBB Tag

I have a simple UBB tag I'm attempting to implement, but it's been less than successful.

Added my simple tag here:

$pattern = array('#\[b\](.*?)\[/b\]#s',
'#\[i\](.*?)\[/i\]#s',
'#\[u\](.*?)\[/u\]#s',
'#\[url\]([^\[<]*?)\[/url\]#e',
'#\[url=([^\[<]*?)\](.*?)\[/url\]#e',
'#\[email\]([^\[<]*?)\[/email\]#',
'#\[email=([^\[<]*?)\](.*?)\[/email\]#',
'#\[color=([a-zA-Z]*|\#?[0-9a-fA-F]{6})](.*?)\[/color\]#s',
'#\[nilbog\](.*?)\[/nilbog\]#s');

And my preg_replace here, which is a call to function do_nilbog:

$replace = array('<strong>$1</strong>',
'<em>$1</em>',
'<span class="bbu">$1</span>',
'handle_url_tag(\'$1\')',
'handle_url_tag(\'$1\', \'$2\')',
'<a href="mailto:$1">$1</a>',
'<a href="mailto:$1">$2</a>',
'<span style="color: $1">$2</span>',
'do_nilbog(\'$1\')');

Now, my PHP is a little fuzzy, but can I call a function within a string literal?  I see it being done here with handle_url_rag, but in my case, it's not calling the function, only (and expected) the variable is being used.

Re: Custom UBB Tag

I assume that you would like to reuse function call (do_nilbog) inside $replace variable which is an associative array, is that true?

if that so you could try to reassigned and points to a string typed value

$new_var = $replace[8];

ps: not sure is that what you mean or not

Re: Custom UBB Tag

Let me rephrase my question:

How is the handle_url_tag() function being called in the parser.php file from within a string?

$replace = array('<strong>$1</strong>',
'<em>$1</em>',
'<span class="bbu">$1</span>',
'handle_url_tag(\'$1\')',
'handle_url_tag(\'$1\', \'$2\')',
'<a href="mailto:$1">$1</a>',
'<a href="mailto:$1">$2</a>',
'<span style="color: $1">$2</span>');

I'm a little confused because the function stored in a string, but somehow being called and properly replacing ubbCode with html tags.

Re: Custom UBB Tag

well.. you can search and find about "PHP Variables and Functions", perhaps from there you can understand how PHP allows you to pass parameters to functions, the ability to call functions dynamically, as well as use variables dynamically, and bla..bla..bla..

its kinda boring you know to talk about it in here big_smile

Re: Custom UBB Tag

Okay, I figured out what I was doing wrong.  For those of you who may have been wondering...:

Add the e flag to your regex pattern.  It'll tell preg_replace to treat your replacement text as code instead of a simple string substitution.

$pattern = '#\[nilbog\](.*?)\[/nilbog\]#e');  // <-- e flag here.
$replace = 'do_nilbog(\'$1\')';  // <-- function here
$text = "[nilbog]Hello![/nilbog]";
preg_match($pattern, $replace, $text);  // $text is now "!olleH"