Displaying photoblog.be entries

Updated 29/07/2004

Some of you might have already noticed the row of five images in the header. These are my five latest post at photoblog.be. I've worked out the script to display them on my own site last night. Took me a couple of hours to work it out, as my php knowledge isn't the greatest. But I got it fixed didn't I!

I knew exactly what the basics of the script needed to do:

  1. open en read the mainpage with the 5 recent post in the left column
  2. filter out the five images
  3. get them displayed on my page
<!--more-->

The first point wasn't a problem at all, nor was the last, but filtering out the five images took me some time. I finally got there thanks to some other scripts I unraveled. Here is the script:

<?php

// enter your photoblog.be username

$photoblog_username = 'sken';

// ----------------------------

$unique_start = '<h4 class="top">recent posts</h4>';
$unique_end = '<h4>my categories</h4>';

$file = 'http://www.photoblog.be/photoblog.php?nickname=' . $photoblog_username;
$handle = fopen($file,'r');

$fd = '';
do {
    $data = fread($handle, 8192);
    if (strlen($data) == 0) {
        break;
	    }
    $fd .= $data;
} while(true);
fclose ($handle);

if ($fd)
{
	$start = strpos($fd, $unique_start);
	$finish = strpos($fd, $unique_end);

	$length = $finish-$start;

	$recent =Substr($fd, $start, $length);
}


$recent = ereg_replace ('<h4 class="top">recent posts</h4>', "", $recent);
$recent = ereg_replace ('uploads', "http://www.photoblog.be/uploads", $recent);
$recent = ereg_replace ('\?nickname', "http://www.photoblog.be/photoblog.php?nickname", $recent);

$recent = ereg_replace ('([0-9]{2})/([0-9]{2})/([0-9]{4})', "", $recent);


echo $recent;


?>

Et voila, it works like a charm. It is however still in beta. And I am going to build in a cache system as soon as possible, because now it has to connect to the site everytime the mainpage is loaded.

I'm sure there are better programmers out ther, so please, don't hesitate to improve my script. If anyone else is interested in using the script, please do so, at own risk, all you have to do is fill in your username at the top and paste the script in a php file.

back to top