MyBB Community Forums

Full Version: Search Highlight destroys preg_replace
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I'm designing a plugin which I use preg_replace in it. For Example:

	$message =preg_replace('#\[plugintag\](.*?)\[/plugintag\]#s',"<div align=\"center\">{$text}</div>", $message);	
This works perfectly, but when a search highlight is given in showthread.php and the highlight word is like a word (or is like the tags) between the plugin tags (or is like the tags), it will be highlighted and the tags will be destroyed and won't functioning!(Like the attached image)
what hook are you using?
(2012-10-04, 06:25 PM)pavemen Wrote: [ -> ]what hook are you using?

parse_message
Try parse_message_start instead - although I guess that might mess with HTML.

parse_message_start is called before html/mycodes/highlights are parsed; parse_message afterwards.

Ugly solution, but you could replace your tags with a random string in parse_message_start and replace the random string with whatever in parse_message. Can't highlight a random string (if it's unique for that post).

A hook for parse_mycode would probably work best but it does not exist.
what you are doing is simply an custom mycode, so you dont need a plugin for that. are you wanting to do something more complex later once the basics are worked out?
(2012-10-04, 09:33 PM)pavemen Wrote: [ -> ]what you are doing is simply an custom mycode, so you dont need a plugin for that. are you wanting to do something more complex later once the basics are worked out?
Yes, This is an example! I want to use a (Really) more complex tag!Huh


(2012-10-04, 09:22 PM)frostschutz Wrote: [ -> ]Try parse_message_start instead - although I guess that might mess with HTML.

parse_message_start is called before html/mycodes/highlights are parsed; parse_message afterwards.

Ugly solution, but you could replace your tags with a random string in parse_message_start and replace the random string with whatever in parse_message. Can't highlight a random string (if it's unique for that post).

A hook for parse_mycode would probably work best but it does not exist.
Thank you but it will show the text between my tags as html codes!