Forum Moderators: coopster

Message Too Old, No Replies

displaying graphical digits for the year

         

lindajames

7:23 pm on Aug 26, 2003 (gmt 0)

10+ Year Member



hello everyone,

on my site i need to put the current year. at the moment i have it like this

<img src="2.gif"><img src="0.gif"><img src="0.gif"><img src="3.gif">

if you look at the above all 4 images combined together displays 2003, i wanted to know how this can automatically be done using php so that every year i do not need to manually change the year. so for example next year it should automatically display the following images:

<img src="2.gif"><img src="0.gif"><img src="0.gif"><img src="4.gif">

i have a directory of all the digits from 0-9

any suggestions would be appreciated.

cheers
linda

panic

7:52 pm on Aug 26, 2003 (gmt 0)

10+ Year Member



$date = date("Y");
$mystring = "$date";
$length = strlen($mystring);
$start = 0;

$output = array();
for($i = 0; $i < $length; $i++){
$output[$i] = $temp_output = substr($mystring, $start, 1);
$start++;
}

foreach($output as $number){
print "<img src=\"$number.gif\">";
}

print "<br>";

bcolflesh

8:34 pm on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ooops - late - my solution:

$yr = date("Y");
$stryr = $yr;
for ($i = 0; $i <= 3; $i++) {
print "<img src=\"";
echo $stryr{$i};
print ".gif\">";
}

bcolflesh

8:36 pm on Aug 26, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ooops - late - my solution:

$yr = date("Y");
for ($i = 0; $i <= 3; $i++) {
print "<img src=\"";
echo $yr{$i};
print ".gif\">";
}

jonknee

11:20 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



Since I like to shorten things, here's my version of bcolflesh's code. Note that I added a path option.


$y = date("Y");
$p = '/images/date/'; //path to images folder
for ($i=0; $i<4; $i++) { echo "<img src='$p" . $y[$i] . ".gif'>"; }

panic

11:41 pm on Aug 27, 2003 (gmt 0)

10+ Year Member



If it works, then it works. Mine will probably slow you down a whole nanosecond or so :(

-p