Flickr图片拉入PHP JSON

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flickr图片拉入PHP JSON相关的知识,希望对你有一定的参考价值。

  1. <?php
  2. $flickrId = 'userId'; // Find your Flickr ID at http://idgettr.com
  3. $flickrrequest = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $flickrId . '&format=json';
  4. $flickrci = curl_init($flickrrequest);
  5. curl_setopt($flickrci,CURLOPT_RETURNTRANSFER, TRUE);
  6. $flickrinput = curl_exec($flickrci);
  7. curl_close($flickrci);
  8.  
  9. // Flickr JSON doesn't come in standard form, some str replace needed
  10.  
  11. $flickrinput = str_replace('jsonFlickrFeed(','',$flickrinput);
  12. $flickrinput = str_replace('})','}',$flickrinput);
  13.  
  14. // parameter 'true' is necessary for output as PHP array
  15.  
  16. $flickrvalue = json_decode($flickrinput,true);
  17. $flickritem = $flickrvalue['items'];
  18.  
  19. // echo the channel information
  20.  
  21. echo "<h3><a href="" . $flickrvalue['link'] . "">" . $flickrvalue['title'] . "</a></h3> ";
  22. echo "<p>" . $flickrvalue['description'] . "</p> ";
  23.  
  24. $photosToDisplay = 5; //change this to the number of photos you want to display
  25.  
  26. for($p=0;$p<$photosToDisplay;$p++){
  27. echo "<a href="" . $flickritem[$p]['link'] . ""><img src="" . $flickritem[$p]['media']['m'] . "" /></a> ";
  28. }
  29.  
  30. echo "<p><a href="" . $flickrvalue['link'] . "">View all my photos</p> ";
  31. ?>

以上是关于Flickr图片拉入PHP JSON的主要内容,如果未能解决你的问题,请参考以下文章

PHP Flickr照片引入PHP JSON

使用 PHP、curl 解码从 Flickr API 返回的 json 字符串

图片轮播 data-slide-to="?"使用 WordPress PHP

从 flickr JSON rss feed 获取所有图像尺寸

用JQuery解析获取JSON数据

从文件名字符串PHP中删除空格[重复]