Display Random Content
Posted by Pete | Posted in PHP Functions | Posted on 13-08-2009-05-2008
0
In this tutorial I will show you how to display random content. This is something similar as to what we use for our adverts on the top of our website. So lets get started.
Random Content From Strings.
<? /** * To create content simply copy the format below * $content[] = "CONTENT HERE"; */ $content[] = "Content 1"; $content[] = "Content 2"; $content[] = "Content 3"; $content[] = "Content 4"; $count = count($content); // Count how many content strings there are. $rand = rand("0", $count); // Pick a random number between 0 and the total $content strings. echo "<div id='content'>".$content[$rand]."</div>"; // Echo the content ?>
So its as simple as that. If you have any further questions or want any more help please leave a comment.


