Need help to make a small plugin ! [SOLVED]
#1
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":


.php   center.php (Size: 687 bytes / Downloads: 164)
.php   right.php (Size: 681 bytes / Downloads: 158)
.php   left.php (Size: 668 bytes / Downloads: 171)

How to include 3 lines like this:
return preg_replace('#\[right\](.*?)\[/right\]#i', "<P ALIGN=\"right\">$1</P>", $message);
in the same function ?
From January 08, 2013:
MyBB Romania - MyBB Community Forums from Romania
Reply
#2
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);
Reply
#3
I can't believe... it's so simple... Shy

It works... here is plugin:
.php   eatbbcode.php (Size: 753 bytes / Downloads: 184)

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
From January 08, 2013:
MyBB Romania - MyBB Community Forums from Romania
Reply
#4
Though you could actually do it with none, using the custom MyCode features Toungue
Reply
#5
blueparukia Wrote:Though you could actually do it with none, using the custom MyCode features Toungue

That's what I was thinking Wink
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)