How to change URL containing img URL into img other link?
<p>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:</p>

<pre><code>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 &lt;img src="http://example.com/images1.jpg" /&gt;text &lt;img src="http://example.com/img/images2.jpg" /&gt; ending text';
$url = '?&lt;=img\s+src\=[\x27\x22])(?&lt;Url&gt;[^\x27\x22]*)(?=[\x27\x22]';
$str_rep = preg_replace($url, foo($url), $str);
echo $str_rep;
</code></pre>

<p>becomes:</p>

<pre><code>text &lt;img src="http://mywebsite.com/images1.jpg" /&gt;
 text &lt;img src="http://mywebsite.com/images2.jpg" /&gt; ending text
</code></pre>

<p>How to fit it ?</p>
