Page 1 of 1

Random two word changer (3 times random)

Posted: Mon Nov 01, 2010 9:00 pm
by hugene13
Hi all,

PHP noob here; I am wanting to know if anyone could help me out with a little thing I am trying to accomplish.

What I need help is I need to change two words each time a page on an html site is refreshed. At random one of the three, two words will be displayed in a paragraph of text. Like so:

1st Option -
This a text in a paragraph.This a text in a paragraph.This a text in a paragraph. The sky is blue.

2nd Option -
This a text in a paragraph.This a text in a paragraph.This a text in a paragraph. The sky isn't red.

3rd Option -
This a text in a paragraph.This a text in a paragraph.This a text in a paragraph. The sky looks green.

I've done the best I could to explain this, let me know if you have nay more questions!

-Eugene

Re: Random two word changer (3 times random)

Posted: Mon Nov 01, 2010 9:58 pm
by Jonah Bron

Code: Select all

$word_set_1 = array('is', 'isn\'t', 'looks');
$word_set_2 = array('blue', 'red', 'green');

$word_1 = $word_set_1[rand(0, 2)];
$word_2 = $word_set_2[rand(0, 2)];

echo 'This a text in a paragraph. This a text in a paragraph. This a text in a paragraph. The sky ' . $word_1 . ' is ' . $word_2 . '.';
rand() produces a random number between the first argument (if present) and the second argument (if present).