• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 177
  • Last Modified:

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
0
bangers3474
Asked:
bangers3474
  • 2
  • 2
1 Solution
 
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
 
German_RummCommented:
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now