Randomly Generate Content





-5
Date Submitted Sat. Mar. 11th, 2006 7:28 PM
Revision 1 of 1
Helper Scriptsentials
Tags "Random Generation" | PHP | Random
Comments 3 comments
This multiple-use PHP script will randomly generate content based on a randomly generated number.

<?php
/*This small script uses the rand() function in PHP to randomly generate desired content. This script is simply an example of how it may be used to generate content. In this script, a certain quote will be displayed depending on the number that is returned by the rand() function.*/

//rand(1, 3) means that the random number will range from 1 to 3.
$number = rand(1, 3);

//These if/else if statements return strings according to the number that was generated.
if($number==1) {
echo "This is the string that will be displayed when the random number is 1!";
}
else if($number==2) {
echo "Since the number was 2, this string was returned!";
}
else if($number==3) {
echo "The number this time was 3!";
}

?>
 
This may seem somewhat basic, but it may be used to do more advanced things such as displaying banners on sites, playing random music clips, or any other use that you could think of. Feel free to ask any questions that you might have.

Randall B.

scriptsentials.com
-----------------------
Proud owner of scriptsentials.com and the Scriptsentials network.

Comments

Comments Ah
Sun. Mar. 12th, 2006 9:43 PM    Helper Scriptsentials
Comments Better code
Sun. Mar. 12th, 2006 5:52 PM    Helper Snyke
  Comments Use external file
Sun. Oct. 29th, 2006 1:03 PM    Scripter SCoon

Voting