Link to home
Start Free TrialLog in
Avatar of bangers3474
bangers3474

asked on

random results parsed on a daily or weekly basis

https://www.experts-exchange.com/questions/21403331/php-to-provide-random-html-for-an-ssi-To-change-daily-weekly-not-just-randomly.html

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

Regards
Bangers
Avatar of jdpipe
jdpipe
Flag of Australia image

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]);

?>
--------------------
Avatar of bangers3474
bangers3474

ASKER

UNless you are German_Rumm please do not answer as points are beiging left open for him,
regards
Bangers
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
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!");
}

?>
ASKER CERTIFIED SOLUTION
Avatar of German_Rumm
German_Rumm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial