random results parsed on a daily or weekly basis

http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21403331.html

Can anyone help with the above.
Tried it but it doesn't work (also no error message).

Regards
Bangers
bangers3474Asked:
Who is Participating?
 
German_RummCommented:
0
 
jdpipeCommented:
Hi bangers

I would go for seeding the random number generator based on the current week value. For example,

Put your text in the array as shown. Or, alternatively, put the names of the files you want to chose from the arrany, and change the 'print' to an 'include'.

-------------------
<?php

// Message of the week
$motw = array(
      "What doesn't kill you makes you fatter"
      ,"A bird in a hand is worth half a dozen of the other"
      ,"Make hay while it's shady"
);

srand(date("W"));

$n = rand(0,count($motw)-1);

print($motw[$n]);

?>
--------------------
0
 
bangers3474Author Commented:
UNless you are German_Rumm please do not answer as points are beiging left open for him,
regards
Bangers
0
 
bangers3474Author Commented:
Sorry jdpipe,
you got in there just before I posted. If I don't here from German_Rumm I'll let you know.

Unfortuneately your method wouldn't work as I will have no control over which files are being added so could not keep on changing the php file to suit,
Thanks for your help though,
regards
Bangers
0
 
jdpipeCommented:
Well while I'm here I might as well make appropriate corrections to above. Includes one of the current '*.htm' files from current directory.

<?php

// Message of the week
$d = dir('.');
$motw=array();
while(false!==($entry=$d->read())){
      if(preg_match("#\\.htm$#",$entry)){
            $motw[]=$entry;
      }
}

if(count($motw)){
      srand(date("W"));

      $n = rand(0,count($motw)-1);

      include($motw[$n]);
}else{
      print("No message of the week yet!");
}

?>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.