I'm trying to use preg_replace and str_replace to wrap all images in with the link being exactly the same as the img src. I have it working so far but it takes out http: and mywebsite.com
Php:
$article_row['copy'] = preg_replace('/(<img [^>]*src="([^"]*)"[^>]*>)/i', '<a href="$2">$1</a>', $article_row['copy']);
$article_row['copy'] = str_replace('src="/', 'style="float:none; width:100%; clear:both; display:block; margin-bottom:10px; margin-top:10px; height:auto !important; " src="' . _SITE_URL, $article_row['copy']);
HTML output
<a href=\"\/ckfinder\/userfiles\/files\/picture.PNG\"><img alt=\"\" height=\"889\" style=\"float:none; width:100%; clear:both; display:block; margin-bottom:10px; margin-top:10px; height:auto !important; \" src=\"http:\/\/mywebsite.com\/ckfinder\/userfiles\/files\/picture.PNG\" width=\"500\" \/><\/a>