Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Random image per week

images php coding issues or problems here.

Moderators: macek, egami, gesf

Random image per week

Postby nsm » Wed Mar 09, 2011 8:12 am

Hi,

I'm using the following code to display a random image per week but can't get it to display the image. It was working but I changed something and now it does not display the images. I also would like to add a link to the image. What am I doing wrong?

<?php
//first of all, get the week:
$d = date("z,w"); // day of year (0..364), day of week (0 Sunday .. 6 saturday)
list($dy,$dw) = explode(",", $d);
$week = intval(($dy-$dw)/7);
if(($dy-$dw)%7) ++$week;
// this calendar starts weeks on sundays, the first partial week is counted
// next, read the file
$images = file('imagelist.txt'); // one image per line
$thisimage = preg_replace("{\r?\n}", "", $images[$week]);
echo "<img src=$thisimage>";

$images1 = file('imagelist1.txt'); // one image per line
$thisimage1 = preg_replace("{\r?\n}", "", $images1[$week]);
echo "<img src=$thisimage1>";
?>
nsm
New php-forum User
New php-forum User
 
Posts: 6
Joined: Thu Feb 17, 2011 8:00 am

Re: Random image per week

Postby johnj » Sun Mar 13, 2011 9:10 pm

Make sure that there is an image for every week in imagelist.txt and imagelist1.txt. For e.g. if $week = 10 then there should be a value for $images[10].
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron