scrape flickr pics (two) cute apes

Now, ungodly ones,
I am gonna tame the wild apes a bit and put them in a cage

I make a DIV and call it the Zoo
and make a table in the zoo
and for the table-cells (“ApesCage”) and images in the cells i apply some extra styles.

[ad#banner-1]

I ripped a css-sheet and worked it around a bit,

.ApesZoo {
  1.  position: relative;
  2. }
  3.  
  4. .ApesZoo table {
  5.  padding: 0px;
  6.  margin: 0px;
  7.  border: 0px;
  8. }
  9.  
  10. .ApesCage {
  11.  overflow: hidden;
  12.  width: 60px;
  13.  height: 36px;
  14.  border: 1px solid #fff;
  15.  padding-top: -3px;
  16. }
  17.  
  18. .ApesCage img {
  19.  margin-top: -6px;
  20.  width: 60px;
  21.  height: 45px;
  22.  border: 0px;
  23. }

Nice, now I put the DIV and TABLE tags and the “CLASS=Apes…” markers in the PHP file, and let her rip

  1. $perrow=5;
  2. $total_images=10;
  3. $mytag="apes";
  4.  
  5. $flikker = join("",file("http://api.flickr.com/services/feeds/photos_public.gne?tags=$mytag&format=rss"));
  6. $flikkerhits = preg_split('/img src=&quot\;/', $flikker, -1, PREG_SPLIT_OFFSET_CAPTURE);
  7. $max=count($flikkerhits);
  8.  
  9. $i=0;
  10. $currentcolumn=1;
  11. $rows=round($total_images/$perrow);
  12. $currentrow=1;
  13. echo "<div class=\"ApesZoo\">";
  14. echo "<table><tbody><tr>";
  15.  
  16. foreach($flikkerhits as $flikkerhit){
  17.     $i++;
  18.     if($i>1) {
  19.   echo "<td class=\"ApesCage\">";
  20.      echo "<img src=\"".substr($flikkerhit[0], 0, strpos($flikkerhit[0], 'width')-7)."\"  />";
  21.   echo "</td>";
  22.   $currentcolumn++;
  23.   if($currentcolumn>$perrow) {
  24.    $currentcolumn=1;
  25.    $currentrow++;
  26.    if($currentrow>$rows) {
  27.     break;
  28.    } else {
  29.     echo "</tr><tr>";
  30.    }
  31.   }
  32.  }
  33. }
  34.  
  35. echo "</tr></tbody></table></div>";

then you get something like this, works fine for me

I moved the width and height specs to the stylesheet, I am gonna be sorry about that later on, but lets just move on to part three, stuff the zoo on the wordpress sidebar

This entry was posted in php, tool and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>