2012-11-21 71 views
0

PHP代碼:獲取圖像的URL在PHP

<?php 

     $url = 'https://www.rudolphs-christmasshop.com.au/api/v2/products/'; 
     $username ='xyz'; $password ='ca25fe6947564b9479sdfsaffsaffasfasfsaffdasfe5866b4'; 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_USERPWD,$username . ':' . $password); 
     $result = curl_exec($ch); curl_close($ch); 
     $xml = simplexml_load_string($result); 

    ?> 

輸出

SimpleXMLElement Object ( 
    [product] => Array ( 
     [0] => SimpleXMLElement Object ( 
      [id] => 29 
      [name] => SimpleXMLElement Object () 
      [type] => physical 
      [sku] => 22254 
      [description] => SimpleXMLElement Object () 
      [search_keywords] => SimpleXMLElement Object () 
      [availability_description] => SimpleXMLElement Object () 
      [price] => 22.9500 
      [inventory_warning_level] => 5 
      [warranty] => SimpleXMLElement Object () 
      [weight] => 0.2500 
      [width] => 13.0000 
      [height] => 11.0000 
      [depth] => 8.0000 
      [view_count] => 125 
      [page_title] => Aussie Koala and Baby Christmas Ornament - Australiana 
      [meta_keywords] => koala bear decoration, koala christmas ornament, australian decorations, aussie christmas, christmas decoration 
      [meta_description] => SimpleXMLElement Object () 
      [layout_file] => product.html 
      [is_price_hidden] => false 
      [price_hidden_label] => SimpleXMLElement Object () 
      [categories] => SimpleXMLElement Object ( 
       [value] => 30 
      ) 
      [downloads] => SimpleXMLElement Object ( 
       [link] => /products/29/downloads) 
       [images] => SimpleXMLElement Object ( 
        [link] => /products/29/images 
       ) 
      ) 
     ) 
    ) 
) 

我怎麼能獲得瀏覽器的圖片網址和顯示圖像

回答

1

可能是錯的,但我想這樣如果我看here

echo $xml->product[0]->downloads->images->link;

但是,如果您向我們展示您的XML,我們就能夠更好地幫助您。

Greets

1

我不能在這裏測試它。不過,您可以訪問樹:

如果你有更多的產品:

<?php 
foreach($xml->product as $pout) { 
    echo $pout->downloads->images->link; 
} 
?> 

如果你想只有一個產品是這樣的:

$xml->product[0]->downloads->images->link;