I have a little problem with some preg_replace functions in PHP.
First I have $message = preg_replace("/\[img\](.*?)\[\/img\]/is", '<img src="$1" alt="" />', $message);
for replacing [img]http://example.com/img.png[/img] with an image. But after that I also have a preg_replace which replaces URLs:
$message = preg_replace("/(?i)\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))/", '<a href="$1">title[$1]</a>', $message);
Is it possible to prevent that the URL within <img src=''
is also replaces with a link? Like putting the URL replace function before the img preg_replace and changing the pattern that it won't change URLs which are within BB-Code brackets?
Thanks for answers!