MyBB Community Forums
Regular extention? - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Development (https://community.mybb.com/forum-68.html)
+---- Thread: Regular extention? (/thread-175248.html)



Regular extention? - marcus123 - 2015-08-19

I am working on hash tags but I have an issue?

I am parsing message with this:


$tweet = $message;
return preg_replace("/#([A-Za-z0-9_]+)(?=\s|\Z)/", '<a href="'.$mybb->settings['bburl'].'/hashtag/\1">#\1</a>', $tweet);
return $message;

This works but stops when the hashtag contains special character!

I am using this expression:


/#([\w]+)/i

It works great simply ignores the special characters but the problem is it also parses quotes, signature and codes.

How to make make this work?


RE: Regular extention? - Ad Bakker - 2015-08-19

(2015-08-19, 04:29 PM)marcus123 Wrote:
$tweet = $message;
return preg_replace("/#([A-Za-z0-9_]+)(?=\s|\Z)/", '<a href="'.$mybb->settings['bburl'].'/hashtag/\1">#\1</a>', $tweet);
return $message;

I don't have much experience with regular expressions but the above php code cannot be good, with 2 return stements after each other. However I suppose the 1st does the same as the 2-nd, when in the 1-sr return is replaced bby $message =