MyBB Community Forums

Full Version: Mycode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm a fanatic of xhtml valid websitesToungue I'd need to know how to make a mycode that sticks to this.

Here is the regular expression:
\[google\](.*?)\[/google\]
and here is the current output
<a href="http://google.com/search?q=$1"><span style="color: blue;">G</span>oogle Search: $1</a>

I need to replace all spaces with %20 all & with &amp; and etc. I just need those two for now, I'll figure the rest on my own later.

Thanks.
Anyone?
Hi Lou,

Is this what you are after, or are you after the button code to auto-wrap the search words ?? Because I'm not really sure I understand the question ?

http://waloc.com/mybb120/showthread.php?...pid=8#pid8

This text works fine,

<a href="http://google.com/search?q=$1" target="_blank"><span style="color: blue;">G</span>oogle Search: $1</a>

with the addition of target="_blank" so that it opens in a new window... Wink
No, I think Lou wants a way to run htmlspecialchars and urlencode on $1, so that the resulting string would still be valid XHTML. I don't know exactly how to do this using regex, but looking at the e modifier (execute PHP code) would be a good place to look.
I can't execute php code in the mycode thing, but if that's the only way to do it, I'll have a look around. I can do this with php so it won't be much of a problem. What will be more of a problem is learning the plugin syntax but it looks simpleToungue Thank's everyone.
Hang on Lou,

The MyCode from what I've learned here today can call many functions...

Have a look here, as it may be of some help in what you are trying to do Wink

I haven't tried any pure .php functions, but I wouldn't be surprised if could handle file inserts such as "fopen" etc.. (or is that perl..... Toungue ROFL!)

http://community.mybboard.net/showthread...4#pid80914
laie_techie Wrote:I don't know exactly how to do this using regex, but looking at the e modifier (execute PHP code) would be a good place to look.
Yeah, but the Custom MyCode feature doesn't support that, so a plugin would have to be used.
Ozidave Wrote:Hang on Lou,

The MyCode from what I've learned here today can call many functions...

Have a look here, as it may be of some help in what you are trying to do Wink

I haven't tried any pure .php functions, but I wouldn't be surprised if could handle file inserts such as "fopen" etc.. (or is that perl..... Toungue ROFL!)

http://community.mybboard.net/showthread...4#pid80914
That doesn't really help...Confused
You can't do this without doing an plug-in out off it. I suggest you look at some of the MyCode plug-ins for 1.2.x series and look at the e modifier in preg_replace aswell as urlencode and htmlspecialchars

Something like:
$plugins->add_hook("parse_message", "google_run");
function google_run($message) {
    return preg_replace('#\[google\](.*?)\[/google\]#ie', "'<a href=\"http://google.com/search?q='.urlencode(htmlspecialchars($1)).'\"><span style=\"color: blue;\">G</span>oogle Search: $1</a>'", $message);
}
CraKteR Wrote:You can't do this without doing an plug-in out off it. I suggest you look at some of the MyCode plug-ins for 1.2.x series and look at the e modifier in preg_replace aswell as urlencode and htmlspecialchars

Something like:
$plugins->add_hook("parse_message", "google_run");
function google_run($message) {
    return preg_replace('#\[google\](.*?)\[/google\]#ie', "'<a href=\"http://google.com/search?q='.urlencode(htmlspecialchars($1)).'\"><span style=\"color: blue;\">G</span>oogle Search: $1</a>'", $message);
}
That would probably work, so I'll have a look at plugin format! Thanks.