Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Random Message Generator
Neutrality
post Feb 24 2005, 02:49 AM
Post #1


Sheathed Motivation
*******

Group: Members
Posts: 126
Joined: 19-February 05
From: Canada
Member No.: 3,868



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".

CODE

$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!
Go to the top of the page
 
+Quote Post
rejected
post Feb 24 2005, 03:34 AM
Post #2


{([Mod])}
*********

Group: Members
Posts: 710
Joined: 30-October 04
From: Texas
Member No.: 2,058



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

CODE
$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];
Go to the top of the page
 
+Quote Post
karlo
post Feb 24 2005, 11:31 AM
Post #3


Privileged Member
*********

Group: Members
Posts: 622
Joined: 30-October 04
From: Philippines
Member No.: 2,049



Before, I readed the PHP manual. And I didn't see the floor function. What's the floor function?
Go to the top of the page
 
+Quote Post
no9t9
post Feb 24 2005, 03:36 PM
Post #4


Privileged Member
*********

Group: Members
Posts: 773
Joined: 4-November 04
Member No.: 2,118



@ rejected
yes, you can put random html code in there as well. that is how some people do random advertisment and banner rotation.

@karlo
i believe the floor function is simple to drop any decimals because he is using that
number as an index for an array. (an array can't have decimal index number)
Go to the top of the page
 
+Quote Post
ill
post Feb 24 2005, 05:07 PM
Post #5


Super Member
*********

Group: Members
Posts: 385
Joined: 10-August 04
From: United States
Member No.: 761



It could also be used to display Random Quotes, which is something a lot of E/N sites do!
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. My Self-coded Message Boards(25)
  2. Just About Completed My Own Message Board Source.(10)
  3. Write Random Text To Image(5)
  4. Imap Problem(1)
  5. Dynamic Image / Signature Generator(12)
  6. Display Random File In A Directory(9)
  7. Forms, Text Files, And Php For A Signature Generator.(1)
  8. Form Generator(9)
  9. How To Make A Random 7 Number Code?(2)
  10. Php - Fetching Random Line From A Text File(0)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 02:18 AM