Jump to content
xisto Community
Neutrality

Random Message Generator

Recommended Posts

Here comes another one of Inspired's "amazing" PHP scripts. This little script lets you display a random message every time the user visits that particular page. It's not really that useful, but it does make the page a bit more "dynamic".

$randMsg = array("Hi, welcome to my page!", "Hey you! Thanks for visiting!","Bonjour, mon ami!", "So, do you like the site?", "Come one, come all!");$MsgNum = count($randMsg);$MsgGenNum = floor(rand(MsgNum));echo $randMsg[$msgGenNum]; 

You can edit those values in the array if you want. Add more if you so choose. Enjoy!

Share this post


Link to post
Share on other sites

Very nice, could you set it to be code snippets? Like

$randMsg = array("<img src='1.gif'>", "<img src='2.gif'>","<img src='3.gif'>", "<img src='4.gif'>", "<img src='5.gif'>");$MsgNum = count($randMsg);$MsgGenNum = floor(rand(MsgNum));echo $randMsg[$msgGenNum];

Share this post


Link to post
Share on other sites

@ rejectedyes, you can put random html code in there as well. that is how some people do random advertisment and banner rotation.@karloi believe the floor function is simple to drop any decimals because he is using thatnumber as an index for an array. (an array can't have decimal index number)

Share this post


Link to post
Share on other sites

It could also be used to display Random Quotes, which is something a lot of E/N sites do!

Share this post


Link to post
Share on other sites
Error In CodeRandom Message Generator

The rand() function takes two parameters: minimum, and maximum.

$id = floor(rand(1,count($quotes)));Echo $quotes[$id];

-reply by Steven

Share this post


Link to post
Share on other sites
Heartfelt ApologyRandom Message Generator

I'm a normal girl.Or so I thought. Sure I grew up decent I guess,I wasn't a tortured soul. I'm still not a tortured soul. But to allow yourself to get swallowed up by society isn't a very decent thing to do. Ignoring lady-like guidelines I single handedly flushed aspects of my life and those of others down the drain. Intense and maybe not consumable (if a word)  to the human mind. But I am very proud. I'm proud of everything that has happened to me through the lessons i have taught others. Even the bad ones where I rudely broke their hearts or even just hurt their feelings. Because its easy to see now, how truly happy they all have become. Everyone finds happiness. Even if your the constant con' in every situation. You and your soul will find eternal happiness. I am Ariel Pirt, and this is my heartfelt apology to all those who couldnt find their happiness,who didn't make it. However I also hope this comes in handy as some sort of motivational type of regard. To each their own, and by that I mean...Be who you are.Because when it all comes down to it, your all you have.

-reply by Ariel

Share this post


Link to post
Share on other sites
**FIX**Random Message Generator

The example is **REJECTED** it have some minor issues:

I fixed it as follow:

$randMsg = array("Hi, welcome to my page!", "hey you! Thanks for visiting!","Bonjour, mon ami!", "So, do you like the site?", "Come one, come all!");$MsgGenNum = floor(rand(1,count($randMsg)));echo $randMsg[$MsgGenNum]; 

Thank you!

-reply by Arturo Garro

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.