How To Create A Random Message Generator Using PHP


Objective: User gets a new message every time; he refreshes the page.

Requirements: Adobe Dreamweaver or any Open Source Editor like Amaya, Aptana Studio etc.

Code:

<?php

$thoughts = “WORK IS WORSHIP

AS YOU SOW, SO YOU REAP

BARKING DOG SELDOM BITE

KNOWLEDGE IS POWER

SHOOT FOR THE MOON, YOU WILL REACH THE STARS

AN APPLE A DAY KEEPS THE DOCTOR AWAY

I AM WHAT, I AM

TO ERR IS HUMAN, TO FORGIVE IS DIVINE

WHEN THE NIGHT IS DARKEST, THE DAWN IS NEAREST

THEY CONQUER WHO BELIEVE THEY CAN

NOTHING IS IMPOSSIBLE

TIME &amp; TIDE WAITS FOR NONE

THINK BEFORE YOU LEAP”;

$thoughts = explode(“n”, $thoughts);

$chosen = $thoughts[mt_rand(0, count($thoughts)-1)];

print $chosen;

?>

4 comments / Add your comment below

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.