Im using the following regex to convert urls to href links. It works great, however ive found a bug with it when using style tags which have a background image.
/** * Convert urls in a string to a html link * @return string */ public static function ConvertUrlsToHtml($str) { $str = preg_replace( '@(?<![.*">])\b(?:(?:https?|ftp|file)://|[a-z]\.)[-A-Z0-9+&#/%=~_|$?!:,.]*[A-Z0-9+&#/%=~_|$]@i', '<a href="\0">\0</a>', $str); return $str; } If i use the following...
<div class="inner-left" style="background-image: url(http://www.somewebsite/background.jpg);"></div> It converts the background image to a href too.
Does anyone know how i can tweak the regex to ignore the style tags?
preg_replace( '@(?<!url\()(?<![.*">])...