scrape flickr pics (two) cute apes
juust | 19/07/2008Now, 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.
I ripped a css-sheet and worked it around a bit,
.ApesZoo {
-
position: relative;
-
}
-
-
.ApesZoo table {
-
padding: 0px;
-
margin: 0px;
-
border: 0px;
-
}
-
-
.ApesCage {
-
overflow: hidden;
-
width: 60px;
-
height: 36px;
-
border: 1px solid #fff;
-
padding-top: -3px;
-
}
-
-
.ApesCage img {
-
margin-top: -6px;
-
width: 60px;
-
height: 45px;
-
border: 0px;
-
}
Nice, now I put the DIV and TABLE tags and the “CLASS=Apes…” markers in the PHP file, and let her rip
-
$perrow=5;
-
$total_images=10;
-
$mytag="apes";
-
-
$flikker = join("",file("http://api.flickr.com/services/feeds/photos_public.gne?tags=$mytag&format=rss"));
-
$flikkerhits = preg_split('/img src="\;/', $flikker, -1, PREG_SPLIT_OFFSET_CAPTURE);
-
$max=count($flikkerhits);
-
-
$i=0;
-
$currentcolumn=1;
-
$rows=round($total_images/$perrow);
-
$currentrow=1;
-
echo "<div class=\"ApesZoo\">";
-
echo "<table><tbody><tr>";
-
-
foreach($flikkerhits as $flikkerhit){
-
$i++;
-
if($i>1) {
-
echo "<td class=\"ApesCage\">";
-
echo "<img src=\"".substr($flikkerhit[0], 0, strpos($flikkerhit[0], 'width')-7)."\" />";
-
echo "</td>";
-
$currentcolumn++;
-
if($currentcolumn>$perrow) {
-
$currentcolumn=1;
-
$currentrow++;
-
if($currentrow>$rows) {
-
break;
-
} else {
-
echo "</tr><tr>";
-
}
-
}
-
}
-
}
-
-
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








