Find and replace URLs from [PHP] and [CODE] tags
Defender Offline
Junior Member
**
Posts: 2
Joined: Nov 2014
Post: #1
Find and replace URLs from [PHP] and [CODE] tags
I am trying to find and replace any type of URL from `code` and `php` tags. I tried this code;

Code:
1
2
3
4
5
6
$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

(This post was last modified: 11-01-2014 11:21 PM by Defender.)
11-01-2014 11:20 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Find and replace URLs from [PHP] and [CODE] tags
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.


My Blog
11-03-2014 11:04 AM
Find all posts by this user Quote this message in a reply
Defender Offline
Junior Member
**
Posts: 2
Joined: Nov 2014
Post: #3
RE: Find and replace URLs from [PHP] and [CODE] tags
Can you please give me any example? I have very limited knowledge in terms of regex. Frown
11-05-2014 06:17 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #4
RE: Find and replace URLs from [PHP] and [CODE] tags
(11-03-2014 11:04 AM)ZiNgA BuRgA Wrote:  You're probably better off taking the regexes MyBB uses in class_parser.php.

My Blog
11-06-2014 05:19 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: