2011-12-15 181 views
1

我從其他網站的鏈接:如何更改鏈接其他網站的鏈接url圖像?

http://www.website1.com/image1.jpg 
http://www.website2.com/image/image2.jpg 
http://www.website3.com/image/url/image3.jpg 

我想從這個網站更改鏈接的URL,我的網站:

http://www.mywebsite.com/image1.jpg 
http://www.mywebsite.com/image2.jpg 
http://www.mywebsite.com/image3.jpg 

我可以使用常規的前?這個想法如何?

回答

0
$new_url = 'http://www.mywebsite.com' + 
substr($url_from_other_website, strrpos($url_from_other_website, '/')); 
2

試試這個:

<pre> 
    <?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)); 
    } 
?> 

輸出:

Array 
(
    [0] => http://www.website1.com/image1.jpg 
    [1] => http://www.website2.com/image2.jpg 
    [2] => http://www.website3.com/image3.jpg 
) 
+0

+1我工作的一個`parse_url`解決方案。 – Herbert 2011-12-15 03:32:30

相關問題