Randomly Generate Content
-5
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!";
}
?>






You learn something new every day.
-----------------------
Proud owner of scriptsentials.com and the Scriptsentials network.
<?php
/*
* This script displays a random string from an array of possible strings.
*/
// Define the strings.
$lines[] = "This is text 1.";
$lines[] = "This is text 2.";
$lines[] = "This is text 3.";
// ...
// Print a random string.
print($lines[rand(0,count($lines)-1)]);
?>
$lines = file('texts.txt');
print($lines[rand(0,count($lines)-1)]);
?>