MyBB Hacks

Full Version: Find and replace URLs from [PHP] and [CODE] tags
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to find and replace any type of URL from `code` and `php` tags. I tried this code;

Code:
$plugins->add_hook("parse_message", "plugin_parse_message");
function plugin_message(&$message)
{
	$error_message_link = 'HIDDEN LINK';
	$message = preg_replace("~(?:https?://)?(?:www\.)(?:[^.\s]+)(?:\.[^.\n\s]+)*\.\w{2,4}(?=(?:(?!\[/?(?:code|php)])[\S\s])*\[/(?:code|php)])~m", "{$error_message_link}","{$message}");
}


but it does nothing at all. Please help me to find a correct REGEX

Your regex is extremely weird - I don't know what you were trying to do with it.  It somewhat works on some contrived examples, but probably not what you want, eg

Code:
http://www.example.com


Also, the 'parse_message' hook is run after MyCodes have been parsed, so trying to do anything to match [code] or [url] tags won't work.
You're probably better off taking the regexes MyBB uses in class_parser.php.

Can you please give me any example? I have very limited knowledge in terms of regex. Frown
(11-03-2014 11:04 AM)ZiNgA BuRgA Wrote: [ -> ]You're probably better off taking the regexes MyBB uses in class_parser.php.
Reference URL's