PHP Date using Images/Graphics

Soldato
Joined
30 Nov 2005
Posts
3,084
Location
London
Strange request but is it possible to use PHP's date function to echo todays date using images?

So I create/export an image from 0-9 and January-December then the PHP displays the correct date using the images.

Tried Google but couldn't find anything.

Perhaps there is a better way?
 
there are a couple of things you could do. You could generate an image using GD2/Image Magick and pass a string representing the date to that. Or you could generate individual images (so 1-31, January - December) and then use the date() function to generate the links to those files.

edit, yeah I think you're talking about the second one.

I'd do something like this:

PHP:
function timestampToImages($timestamp){
    $day = date('j',$timestamp);
    $nums = str_split((string)$day);
    $month = strtolower(date('l',$timestamp));
    $formula = '<img src="/path/to/img/%s.png" alt="%s"/>';
    foreach ($nums as $num){
        printf($formula,$num,$num);
    }
    printf($formula,$month,$month);
}
timestampToImages(time());
that should do you.
 
Last edited:
Back
Top Bottom