PHP - RANDOM TEXT
Here's how you can display a random link or text from a text file.
Create a new file called
random.php. Copy this code into it and save it. This is the script that will retrieve a random entry from random.txt.
PHP Code:
<?
$textfile ="random.txt";
$items = file("$textfile");
$item = rand(0, sizeof($items)-1);
echo $items[$item];
?>
Now you've got to create another new file, this time a
text file. This is where you enter the links (as HTML) or text, make sure each entry is on its
own line. Save it as
random.txt
Use this code where you want the random event to appear:
PHP Code:
<? include 'http://www.YOURSITE.com/random.php' ?>
That's it.