dsyak22488 2012-11-21 12:23
浏览 41

通过php中的xml获取图片网址

php code:

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

    ?>

output

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

How could I get the image url and display image on browser

  • 写回答

2条回答 默认 最新

  • douyueqing1530 2012-11-21 13:32
    关注

    May be wrong but I guess like this if I look here

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

    But if you show us your XML we are more able to help you.

    Greets

    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败