What's a regex pattern (in PHP) that replaces img string with links, where tag img URL is used as the anchor text for the link? For example:
function foo($uri) {
$url = parse_url($uri);
$paths = explode('/', $url['path']);
return sprintf("%s://%s/%s", $url['scheme'], 'http://mywebsite.com', end($paths));
}
$str='text <img src="http://example.com/images1.jpg" />text <img src="http://example.com/img/images2.jpg" /> ending text';
$url = '?<=img\s+src\=[\x27\x22])(?<Url>[^\x27\x22]*)(?=[\x27\x22]';
$str_rep = preg_replace($url, foo($url), $str);
echo $str_rep;
becomes:
text <img src="http://mywebsite.com/images1.jpg" />
text <img src="http://mywebsite.com/images2.jpg" /> ending text
How to fit it ?