In this tutorial, I will show you how show random content or you could use this tutorial show random advertisement.
The Full PHP Code
<?php
$fcontents = join ('', file ('somefile.txt'));
$s_con = split("~",$fcontents);
$banner_no = (rand()%(count($s_con)-0));
echo $s_con[$banner_no];
?>
PHP code explaination
The First Part:
The First part of the code will get the file.
<?php
//opening the text file, if this line gives you error when compiling
//then you need to chmod 755 your text file
$fcontents = join ('', file ('somefile.txt'));
The Second Part:
This part will split the content by ~
//Spliting contents of file by looking for ~ mark between contents
//and storing everything into an array.
$s_con = split("~",$fcontents);
The Last Part:
//getting a random number which will be within the limit of the
//contents of the file, means if 5 different banners/ads/contents then the number
//will be between 0-4 (total 5 )
$banner_no = (rand()%(count($s_con)-0));
//simple echo the content
echo $s_con[$banner_no];
In the .TXT File
Your First Code or Content
~ <<< Make Sure to add this after each code or content
Your Second Code or Content
To show the content in your page, just include the .php file which has the code above within.
<?php include('path to your php file'); ?>
Enjoy!
[MY_P2L_AD]