khalilov
Jul 21 2008, 12:21 PM
| | Is there a PHP script that randomly selects a string from a list? example, the list is: 1-Pie 2-Balls 3-eggs The script would view a random word from those 3 every time i run it.
Also is there a function that gives a random number between 0 and a number i select? |
Reply
faulty.lee
Jul 21 2008, 07:03 PM
QUOTE(khalilov @ Jul 21 2008, 08:21 PM)  Is there a PHP script that randomly selects a string from a list? example, the list is: 1-Pie 2-Balls 3-eggs The script would view a random word from those 3 every time i run it.
Also is there a function that gives a random number between 0 and a number i select? Here is your random number generator -> http://my2.php.net/randAll you need is to call the rand() function. If you want to generate a random number between 0 to x, then just call CODE rand(0, x); As for your random string, all you need is to extend the rand function a little bit CODE $strCol = array("Pie", "Balls", "eggs"); $i = rand(0, count($strCol) -1); echo $strCol[$i]; This is how it works. First you create an array of string for your list. Then calling rand and passing it 0 as min, and max would be array count - 1. You need to minus 1 because index is zero based. After that just index your array using the random number you got. With this setup, you can easily add more string to your array and the rest is taken care of automatically
Reply
Mike gambino
Jul 25 2008, 03:30 AM
QUOTE(khalilov @ Jul 21 2008, 08:21 AM)  Is there a PHP script that randomly selects a string from a list? example, the list is: 1-Pie 2-Balls 3-eggs The script would view a random word from those 3 every time i run it.
Also is there a function that gives a random number between 0 and a number i select? wow that's cool. I would like that but on my game website would be a lot more advanced than that. I have a LONG code for that one but it is hard to type it down for on thing. right now I have to get my website fully done. I will let people look at my website when it is done though.
Reply
Recent Queries:--
random selector software - 13.09 hr back. (1)
-
random word selector - 18.55 hr back. (1)
-
php select random array - 70.84 hr back. (1)
-
php save rand() as string - 96.85 hr back. (1)
-
random code php time - 101.29 hr back. (1)
-
random text tool - 108.69 hr back. (1)
-
php random string selector - 235.44 hr back. (1)
-
random ball selector - 269.42 hr back. (1)
-
random selector - 386.07 hr back. (1)
Similar Topics
Keywords : php, random, selector, whats, code
- Activation Code
(7)
Dynamic Php Image And Better Php Code Question
(10) Im working on a dynamic image, can i put 2 images in same dynamic image, and can i make this code
shorter? if ( $goal == 31 ) { $xp2 = ('14833'); } elseif ( $goal == 32 ) { $xp2 =
('16456'); } elseif ( $goal == 33 ) { $xp2 = ('18247'); } elseif ( $goal == 34 ) {
$xp2 = ('20224'); } elseif ( $goal == 35 ) { $xp2 = ('22406'); } elseif ( $goal ==
36 ) { $xp2 = ('24815'); } elseif ( $goal == 37 ) { $xp2 = ('27473'); } elseif (
$goal == 38 ) { $xp2 = ('30408'); } elseif ( $goal == 39 ) { $xp2 = ('33648')....
Random With Functions?
(4) Hey! Is it possible to use a random script on functions. Lets say I have created three functions
(Items that a user will win if he defeates a monster). One function is a function named shield()
and another function is named sword() and a third function is named helmet(). Now when a player
defeates a monster, he must be awarded. So.. How can I randomize what item he should get? something
like CODE rand(sheild(), sword(), helmet()); or? Thanks //Feelay....
What's Wrong With My Php Webpage?
there may be something wrong in my php code. (2) This is the first time I use the functions fopen() and preg_replace() . It seems that there's
somthing wrong. Where did I write by mistake? CODE include('data/workinfo/0.php');
$viewwork = substr($work ,0,249); /* HERE CAN'T WORK WELL! */ $newthread =
fopen("http://c8s2007.freetzi.com/bbs/new.php?action=article&digest=0&postdate=0&author=1&fname=0&hi
ts=0&replies=1&pre=6&num=10&length=35&order=1", "rb"); if(!$newthread){ $newthread =
"无法调用信息!"; }else{ $ad = "
"; ....
Random Name Generator
For a fantasy RPG forum (2) Well, I did this particular piece of coding a few days back, and I forgot to display it to you all
here at AstaHost. I have just started a fantasy RPG forum. The naming rules are pretty strict
because it has to be based on a construted langage called Pasen. No matter how much I explained, I
thought, it would be hard for a newbie to understand the syllable formation constraints. Hence, I
wrote a script and put it at my Drupal powered site, that generates random names for the four races
for both genders. http://www.WiseTome.com/name-generator-for-chaos-and-order I ....
Code Snippets Repository
(0) Well as everybody know in these forums people posts a lot of code snippets that could be organized
in a simple page or whatever, my question is if someone is interested to do it or if exists
something like that here at astahost. I think it would be very helpful for everybody as well to
keep things more organized. Best regards,....
Script For Viewing A Random Image Needed
(3) While browsing the web, I bumped into a script that I could really use, since it's different
from everything that I saw. Most scripts that view a random image contain a code that chooses an
image, and then puts the part into the page itself. However, on the www.greenplastic.com web
site (dedicated to Radiohead), in the top left corner there is a random image module. If you look at
the code, here's what is used: CODE Now, how can a PHP script be an image, and what
kind of script that is? If you do visit that URL , you don't get a normal page, b....
How Can I Write PHP Code By This Formmail Html
(5) purpose is i want the information in the web page sent into my email. i just know that i need to use
php script to operate this action ,but i have no idea about this php code. so anyone can help me
please... thank you very much. ชื่อ
....................... ....... นามสกุล
....... ชื่อเล่น
วันเกิด 1 2 3 4 5 6 7 8 9 10 11
12 13 14 15 16 ....
[PHP + MySQL] Separating The Results By Pages
Simple code (0) Hi! I will post here a code for separating the results of MySQL in pages. You ask: Why separete? I
answer: Imagin that you have 1523 results to display. I dont have to say anything. =P Here is it.
------------------------------------------------------------------- CODE $conect =
mysql_connect("host","user","password"); $select_db = mysql_select_db("database"); $query = "SELECT
* FROM mytable"; $results = "15"; //Number of results displayed per page. if (!$page) {
$counter = "1"; } else { $pcounter = $page; } $start = $counter - 1; $start = $counter *
$resu....
What's Wrong With This Preg_replace Code?
(2) I have written a JavaScript that prompts auser for 5 table attributes for entry into the posting
area and it produces this: It is then passed through this preg_replace for display in the
preview or as a submission in a post: CODE $txt = preg_replace( "#\ (.+?)\ #is", " \\6 ", $txt
); What it produces however is this: CODE When what I want is this: CODE
What is it that is wrong with this code and giving this odd unwanted result? Help would be most
certainly appreciated because I am tired of looking at it, my eyes are getting crossed ....
Any Tool/software For Php Code Generation ?
Tool for code generator (3) Where find any tool to generate PHP class?....
Php: Write Random Text As Image
Having problems, help needed! (3) I'm trying to create a script that writes text to an image. CODE header("Content-type:
image/png"); $_phrases = array( "Test 1", "Test 2", "Test 3", "Test 4", "etc." ); $_rand_phrase
= $_phrases ; $_image = imagecreatefrompng("gmail.png"); $_user_width =
imaagettfbbox(9,0,"tahoma.ttf",$_rand_phrase); $_x_value = (200-($user_width + 113)); $_color =
imagecolorallocate($_image, 165, 164, 164); imagettftext($_image, 9, 0, $_x_value, 16, $_color,
"tahoma.ttf", $_rand_phrase); imagepng($_image); imagedestroy($_image); I can't see what
I'm doing wron....
How To Use Cookie In Your Web Site ?
this semple code to use and get cookie (1) what is the cookie ? the cookis it is some info sent and save in user computer whare i can use the
cookies? becouse the cookies it like the header you can not send it after any output wes sent so
you must send the cookies before any output like as ,echo and any other code i well make an E.X.
to use the cookies you must have 2 file index.php update.php ---------- in the index.php add this
code CODE // This section must go at the top of the page that will display // the
users favorites. These are the 'default' URLs that the user // will se....
Php Reading And Writing To File
the code is very esay (4) this code to Read from file you can use this code in to make a small data base and it is very to
use CODE $fp = fopen ("file.txt", "r"); $bytes = 4; $buffer = fread($fp, $bytes); fclose
($fp); print $buffer; ------------------- to write to same file CODE $fp = fopen
("file.txt", "w+"); fwrite ($fp, "Test"); fclose ($fp); ---------------- thanks and iwait
the commant....
Php Random Text Generating
How to Generate Random Text (4) I was trying to figure out how to make random texts for random passwords and stuff, and I found
someone who created this code. QUOTE //author: polmme $codelenght = 10;
while($newcode_length $x=1; $y=3; $part = rand($x,$y); if($part==1){$a=48;$b=57;} // Numbers
if($part==2){$a=65;$b=90;} // UpperCase if($part==3){$a=97;$b=122;} // LowerCase
$code_part=chr(rand($a,$b)); $newcode_length = $newcode_length + 1; $newcode = $newcode.$code_part;
} echo $newcode; ?> I think it's pretty good. If anyone has a better one or suggestions,
please tell me.....
Random Banners Rotation...
set by percentages (2) alright, I know a few different ways to make a random banner with php - where a different banner
would rotate with every refresh/click. But I've had some "customers" complain how they think
their banner should show up more then others for one reason or another, and I completely agree with
them. So now I kinda want to have a code (most perferably php or javascript) that would have the
banner rotation where I could set a peticular banner to show up say 15% of the time and another 5%
so I could satisfy my more loyal members over the ones simply looking for more hits to ....
Random Image / Random Header
S.O.S. (5) im building a website, and i need some help i got 3 frames, navigation, top and main, but i want
the top banner to have a new tagline with every refresh, just like the header, it dont really matter
what coding it is, as long as it's not to weird /tongue.gif' border='0'
style='vertical-align:middle' alt='tongue.gif' /> ....
Page Doesn't Load When This Php Code Is Present ?
(6) CODE switch($_GET ) { case "home"; include("index.php"); break; case
"gallery"; include("gallery.php"); break; case "links"; include("links.php");
break; case "guestbook"; include("../guestbook/"); break; case "portfolio";
include("portfoilio.php"); break; case "other"; include("other.php"); break;
case "about"; include("about.php"); break; case "contact";
include("contact.php"); break; case "login"; include("/private/"); break;
default....
Looking for php, random, selector, whats, code
|
*SIMILAR VIDEOS*
Searching Video's for php, random, selector, whats, code
|
advertisement
|
|