Random Text

By Will26 on Jul 16, 2005

This snipplet is great if you want to display random text great if you want to display a new tip each time page is refreshed or visited.

Can be altered to do other things such as display random advertisement.

$random_text = array("Random Text 1",
                    "Random Text 2",
                    "Random Text 3",
                    "Random Text 4",
                    "Random Text 5");
$sizeof = count($random_text);
$random = (rand()%$sizeof);


Sign in to comment.
surio   -  Jun 10, 2016

http://vihuni.com i cant spin text

srisoftwarez   -  Nov 16, 2009

is there any other way to do this ...

bone282   -  May 16, 2009

array_rand is handy for getting random values:


from a file:

$file = file("randomquotes.txt");

tye   -  Aug 29, 2005

Using srand() before rand() isn\'t necessary for PHP 4.2.0+. rand() also takes two parameters like this:


This code could be simplified to:
print($random_text[rand(0,count($random_text) - 1)]);

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.