MyBB Community Forums

Full Version: Need help to make a small plugin ! [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hy.

I need help please.

This is 3 small plugins for my own forum which give me possibility to align text with this 3 bbcodes:
[left]text align to left[/left]
[right]text align to left[/right]
[center]text align to left[/center]

But I want to make just ONE plugin for all and I don't know how...
I think is not so hard...

Can you help me, please ?

Here is "plugins":

[attachment=9006][attachment=9005][attachment=9004]

How to include 3 lines like this:
return preg_replace('#\[right\](.*?)\[/right\]#i', "<P ALIGN=\"right\">$1</P>", $message);
in the same function ?
You should look into how variables and how arguments are passed to functions. Looking at how regular expressions work also help.

In your case, you can just store each thing to a variable, eg:
$message = preg_replace('#\[right\](.*?)\[/right\]#i', "<P ALIGN=\"right\">$1</P>", $message);
$message = preg_replace('#\[left\](.*?)\[/left\]#i', "<P ALIGN=\"left\">$1</P>", $message);
$message = preg_replace('#\[center\](.*?)\[/center\]#i', "<P ALIGN=\"center\">$1</P>", $message);
return $message;
Or you could stack the preg_replace's together:
return preg_replace('#\[right\](.*?)\[/right\]#i', "<P ALIGN=\"right\">$1</P>", preg_replace('#\[left\](.*?)\[/left\]#i', "<P ALIGN=\"left\">$1</P>", $message));

//etc

Or, simply, use proper regexes:
return preg_replace('#\[(left|center|right)\](.*?)\[/\\1\]#i', "<P ALIGN=\"$1\">$2</P>", $message);
I can't believe... it's so simple... Shy

It works... here is plugin: [attachment=9010]

I already have on my forum over 75 plugins and I really don't want to have another 3.
So, with your help, I have just 75+1 Toungue

Thank you so much, ZiNgA BuRgA !
Smile
Though you could actually do it with none, using the custom MyCode features Toungue
blueparukia Wrote:Though you could actually do it with none, using the custom MyCode features Toungue

That's what I was thinking Wink