0

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 
                )
            )
        )
    )
)

如何获取图像 url 并在浏览器上显示图像

4

2 回答 2

1

可能是错的,但如果我看这里,我想是这样的

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

但是,如果您向我们展示您的 XML,我们将更有能力为您提供帮助。

问候

于 2012-11-21T13:32:27.323 回答
1

我不能在这里测试它。但是您可以通过以下方式访问树:

如果您有更多产品:

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

如果您只想要一种产品,如下所示:

$xml->product[0]->downloads->images->link;
于 2012-11-21T13:33:53.160 回答