Neutrality 0 Report post Posted February 24, 2005 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
rejected 0 Report post Posted February 24, 2005 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
karlo 0 Report post Posted February 24, 2005 Before, I readed the PHP manual. And I didn't see the floor function. What's the floor function? Share this post Link to post Share on other sites
no9t9 0 Report post Posted February 24, 2005 @ 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
ill 0 Report post Posted February 24, 2005 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
iGuest 3 Report post Posted June 14, 2009 Error In CodeRandom Message GeneratorThe 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
iGuest 3 Report post Posted July 30, 2009 Heartfelt ApologyRandom Message GeneratorI'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
iGuest 3 Report post Posted August 13, 2009 **FIX**Random Message GeneratorThe 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
unitechy 0 Report post Posted August 19, 2009 I just tested this one on localhost, It does not display any message. Are you sure that echo $randMsg[$MsgGenNum]; is correct line? Share this post Link to post Share on other sites