Repair link url mywebsite from other link
<p>Here in my code:</p>

<pre><code> &lt;?php
    $urls = array('http://www.website1.com/image1.jpg',
                  'http://www.website2.com/image/image2.jpg',
                  'http://www.website3.com/image/url/image3.jpg'
    );
    while(list($i, $uri) = each($urls)) {
    $urls[$i] = foo($uri);
    }
    print_r($urls);

    function foo($uri) {
    $url = parse_url($uri);
    $paths = explode('/', $url['path']);
    return sprintf("%s://%s/%s", $url['scheme'], $url['host'], end($paths));
    }
    ?&gt;
</code></pre>

<p>output</p>

<pre><code>Array
(
    [0] =&gt; http://www.website1.com/image1.jpg
    [1] =&gt; http://www.website2.com/image2.jpg
    [2] =&gt; http://www.website3.com/image3.jpg
)
</code></pre>

<p>How to fix output for this result:</p>

<pre><code>Array
    (
        [0] =&gt; http://www.mywebsite.com/image1.jpg
        [1] =&gt; http://www.mywebsite.com/image2.jpg
        [2] =&gt; http://www.mywebsite.com/image3.jpg
    )
</code></pre>
