I want to replace a part of a string but ignore some other parts of it. I have pattern but don't know how to use it.
$message = '<div class="sacred">http://www.daniweb.com/ is inside the div tag so I do not want it replaced.</div>http://www.google.com/ is outside the div tag so I do want it replaced';
$exclude = '<div class=\"sacred\">.*?<\/div>';
$pattern = '/(https?\:\/\/.*?\..*?)(?=\s|$)/i';
$message= preg_replace($pattern, '<a href="$1" target="_blank">$1</a>$2', $message);
How do I tell preg_replace to ignore everything that is in the <div class="sacred">....</div> parts of the string?
Thanks in advance.