coolcat50
Feb 2 2008, 09:40 PM
For some reason my random string script is not working. I got a fatal error when I tried it under XAMPP. I do not know why. It looks syntatically correct. Could someone help me? Here is the script: (Warning its over 100 lines long) CODE <?php //This PHP script will generate a random array and turn it into a string consisting of 0-9 and A-Z. // This is the first developmental version.
//Create 10 item array for string $string = array(0,0,0,0,0,0,0,0,0,0);
//Create function to replace 10-36 with A-Z function conToStr() { for ($a = 0;$a<=9;$i++) { switch($string[$a]) { case 10: $string[$a] = 'a'; break; case 11: $string[$a] = 'b'; break; case 12: $atring[$a] = 'c'; break; case 13: $string[$a] = 'd'; break; case 14: $string[$a] = 'e'; break; case 15: $string[$a] = 'f'; break; case 16: $string[$a] = 'g'; break; case 17: $string[$a] = 'h'; break; case 18: $string[$a] = 'i'; break; case 19: $string[$a] = 'j'; break; case 20: $string[$a] = 'k'; break; case 21: $string[$a] = 'l'; break; case 22: $string[$a] = 'm'; break; case 23: $string[$a] = 'n'; break; case 24: $string[$a] = 'o'; break; case 25: $string[$a] = 'p'; break; case 26: $string[$a] = 'q'; break; case 27: $string[$a] = 'r'; break; case 28: $string[$a] = 's'; break; case 29: $string[$a] = 't'; break; case 30: $string[$a] = 'u'; break; case 31: $string[$a] = 'v'; break; case 32: $string[$a] = 'w'; break; case 33: $string[$a] = 'x'; break; case 34: $string[$a] = 'y'; break; case 35: $string[$a] = 'z'; break; default: //Number is 0-9 //We just keep it as it is $string[$a] = $string[$a]; } } }
//Create rand number loop for array sections and insert rand num into array. for ($i=0; $i<=9; $i++) { //Start rand function $string[$i] = rand(0,35); }
//Perform the conToStr() function with no arguments conToStr();
//Put the array into another variable as a string $product = implode('',$string);
//Echo out the string echo $product ?>
Reply
rvalkass
Feb 3 2008, 10:15 AM
The variable $string is created outside of the function conToStr(). This means that conToStr() cannot actually access that variable. I assume this is where you are getting some errors. You'd need to either make that variable global, define it within the function, or pass it to the function as an argument. Secondly, the for loop inside conToStr() will run endlessly, hence the fatal error. You want it to stop when $a reaches 10, yet you are increasing the variable $i. Not only does $i not exist (so you can't increment it), but $a is never actually increasing, so the loop never ends. PHP aborts it after 30 seconds of going in an infinite loop. This section... CODE //Create rand number loop for array sections and insert rand num into array. for ($i=0; $i<=9; $i++) { //Start rand function $string[$i] = rand(0,35); } ...is pointless. You never use the variable $string, so putting 10 random numbers in it is a waste of time - they never actually get used as they are not passed to the function. The key point is that the function can only use variables that are... - Globals
- Defined within the function itself
- Passed to the function as arguments
Reply
coolcat50
Feb 3 2008, 06:31 PM
I think you might have just fixed my script. Thanks Rvalkass! Also, I use the $string array to get rand numbers and replace 10-35 with letters. That is the only way I know how to randomize letters. EDIT:I made the $string array global inside of the function and changed the $i++ to $a++ and it now works. Completed script: CODE <?php //This PHP script will generate a random array and turn it into a string consisting of 0-9 and A-Z. // This is the first developmental version.
//Create 10 item array for string $string = array(0,0,0,0,0,0,0,0,0,0);
//Create function to replace 10-36 with A-Z function conToStr() { global $string; for ($a = 0;$a<=9;$a++) { switch($string[$a]) { case 10: $string[$a] = 'a'; break; case 11: $string[$a] = 'b'; break; case 12: $atring[$a] = 'c'; break; case 13: $string[$a] = 'd'; break; case 14: $string[$a] = 'e'; break; case 15: $string[$a] = 'f'; break; case 16: $string[$a] = 'g'; break; case 17: $string[$a] = 'h'; break; case 18: $string[$a] = 'i'; break; case 19: $string[$a] = 'j'; break; case 20: $string[$a] = 'k'; break; case 21: $string[$a] = 'l'; break; case 22: $string[$a] = 'm'; break; case 23: $string[$a] = 'n'; break; case 24: $string[$a] = 'o'; break; case 25: $string[$a] = 'p'; break; case 26: $string[$a] = 'q'; break; case 27: $string[$a] = 'r'; break; case 28: $string[$a] = 's'; break; case 29: $string[$a] = 't'; break; case 30: $string[$a] = 'u'; break; case 31: $string[$a] = 'v'; break; case 32: $string[$a] = 'w'; break; case 33: $string[$a] = 'x'; break; case 34: $string[$a] = 'y'; break; case 35: $string[$a] = 'z'; break; default: //Number is 0-9 //We just keep it as it is $string[$a] = $string[$a]; } } }
//Create rand number loop for array sections and insert rand num into array. for ($i=0; $i<=9; $i++) { //Start rand function $string[$i] = rand(0,35); }
//Perform the conToStr() function with no arguments conToStr();
//Put the array into another variable as a string $product = implode('',$string);
//Echo out the string echo $product ?>
Reply
jlhaslip
Feb 3 2008, 07:23 PM
If the array of values is fixed, never changing, try this code on for size. It uses the shuffle function to randomize the array so you save the switch statement. CODE <?php // define the starting array and the output variable $input = array( '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' ); $out = '';
// randomize the array of values shuffle($input); // loop through the required number of array values, concatenate the value to the output variable for ($i = 1; $i <= 9; $i++) { $out .= $input[$i]; }
// output the $output here echo $out; ?> Might make a fair Password Generator??? Adjust the length from inside the for loop to add characters, possibly Uppercase, as well???
Reply
coolcat50
Feb 3 2008, 07:28 PM
Wow! My script is so complicated compared to that one. Well, I might make a password generator. Do you mind if I use your code snippet for it?
Reply
jlhaslip
Feb 3 2008, 07:44 PM
Nope, I don't mind at all. Glad to assist. maybe I'll make one and we can compare notes???
Reply
coolcat50
Feb 3 2008, 08:08 PM
Hmm yeah! I may use yours if mine becomes too long, but I want to see if I can make mine do some cool stuff. It will look more professional if it's longer. Laugh out loud!
Reply
Recent Queries:--
jack-retasking via script - 366.82 hr back. (1)
-
"randomize letters" word - 989.17 hr back. (1)
Similar Topics
Keywords : script, working,
- Need Help With Javascript Drag And Drop Script
Having trouble with javascript drag and drop script. (2)
Java Script To Hide The Url In Address Bar
Does any one know about this ? (6) Hello friends , just now i came accross a particular type of script which is capable of masking the
URL which is seen in the Address bar of the webpage , that is by implementing the particular Java
Script when the user visits a page eg. www.mysite.com , then it is possible for the admin of
www.mysite.com to mask this site and display some other website in the viewers address bar. I came
to know that such a script can be written using Java Scripts , Can any one get me the Script ??....
[request] Avatar For Trap17 Users
Nice one... for my avatar rotator script (0) As per the description above, I would like to challenge the GFX people here on the Trap17 to design
a nice, bright, clear, professional looking 'avatar' for me and other members to use. I
plan on including it in my Rotator Script, which I think can be found in the Tutorial Section here
on the Trap17. (If not, I must write that one soon). /laugh.gif" style="vertical-align:middle"
emoid=":lol:" border="0" alt="laugh.gif" /> I'm thinking that we need to open this up as a
Competition so all Members can contribute and then the Admins can start a new section in ....
Mysql Database Not Working
(3) well i'm getting an error message(a databass connection warning) for all of the parts of my site
that connects to a mysql database i check my database users pertmissions and i try to do the repair
database thing and it's still not woeking. am i the only person having this or is it an overall
trap17 issue and how do i fix it.....
Seeking Help With Javascript
Need help with drag and drop type script (1) What i want to make is a script that has a table, which is a menu for my site, and when you click
the top of the table you can drag it to another place in the page. This is the code: Test
run - Right click menu - ©Jack McCrea 2008 <script type="text/javascript"> function
coordinates(event) { if (event.button==2) { var x=event.x; var y=event.y;
document.getElementById("element").style.left=x; document.getElementById("element").style.top=y;
document.getElementById("element").style.visibility="visible"; var oldx=x; var oldy=y; } }
<script type="....
Browser Compatibility Problem With Firefox - Javascript + Css
Having trouble making a script work right - any suggestions? (3) Hi, Im working on a website, and im trying to make a right-click menu, which opens on right click,
wherever the cursor is, and closes on mouse out. I wrote the code below, and when i ran it in IE it
ran fine, just how i wanted it to work. However in firefox, the menu just opened in the top left. im
presuming this is because it doesnt like my style changing in the javascript. Any ideas, and
suggestions? If i cant make this work, i will just make it so it works slightly differently when
viewev in firefox so that it can just open in one place. All ideas appreciated. ....
Hosting Application Is Not Working For Me
(2) it says since i have already filled out an application, i can't fill out another one even after
my account was deleted for non activity. anyway, i can either fill out the form when it's ready
for me to fill out or my other application is here...
http://www.trap17.com/forums/index.php?sho...wildcat-exotics everything is the same except instead
of wildcat-exotics.trap17.com, i would like the domain "wildcatexotics.com". same as before
/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />....
How To Make Php Newsletter Script
(3) I have seen a post on here somewhere which shows how to make a simple newsletter php script. I
cvant find it anywhere and I wanted to ask some questions of the author. Does anyone know the one I
mean? Cheers ....
Php Guest Online Script
(3) make an index.php copy and paste this code CODE <?php $db_host = "localhost";
$db_user = "root"; $db_pass = ""; $db_name = "test";
$dbc = mysql_connect($db_host, $db_user, $db_pass); $dbs =
mysql_select_db($db_name); $tm = time(); $timeout = $tm -
(30*60);
if($_SERVER["REMOTE_ADDR"]){$ip=$_SERVER["REMOTE_ADDR
"];} else{$ip=$_SERVER["HTTP_X_FORWARDED_FOR"];}....
Gallery Not Working
(2) Alright, the Gallery module from Fantastico always used to work for my site. Now it's suddenly
stopped functioning and I can't even access the control panel for it. My Iframe page linking to
it gives one long error message: QUOTE Error Error (ERROR_STORAGE_FAILURE) : * in
modules/core/classes/GalleryStorage.class at line 226 (GalleryCoreApi::error) * in
modules/core/classes/GalleryStorage.class at line 453 (GalleryStorage::_getConnection) * in
modules/core/classes/Gallery.class at line 202 (GalleryStorage::search) * in
modules/core/classes....
Sound Card Not Working Properly.
Jack retasking functionality missing (5) Hi, I recently switched to a new motherboard ASUS P5Q. At first I liked the motherboard because of
the features it has to offer but now its a complete turn-off First thing that I noticed was Realtek
ALC1200 (thats the sound card) on this board is not allowing Jack retasking on the back panel. I
don't have any front connections since my cabinet doesn't have these. Is this a problem or
is it normal? I had Realtek audio in my other board (XFX 650i Ultra /sad.gif"
style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> ) but this is the first time
i....
Guessing Php Script
(2) I am looking for: freeware php quess the person in the photo game script....
Help For My Seagate Sata Hard Drive!
hard drive stops working randomly, please help! (9) I just bought that disk (seagate SATA 500G) half year ago and found it stop working randomly,
resulting the whole system to be dead. BTW, I am using Win XP. I tried to use seatool, provied by
seagate, to scan and repair the error, the program stop at the half of the process. I even can't
format entirely, just do quick format. I don't know what I can do and have been pissed off for a
few days. hope some people have this kind of experience and give me any idea. I don't want to
loss my 500G data storeage. thanks in advance.....
Login Script For Vbulletin.
(9) For some reason when I try to logon from the main page it doesnt work, it just brings me to the
forums unlogged. Anyone here have any ideas whats wrong with my coding? Heres the webpage:
www.ageofilluminati.com Heres the coding im Using: QUOTE
Forgot password? Register for free! ....
Php Downloads Script
(4) I've been looking all over the net for a PHP script which can provide an interface to browse a
downloads database. The database could be powered by MySQL. If you know a script like this, please
post it here. Thanks in advance, Ironchicken.....
Very Simple Online Now Script
This is a very simple online now script. (4) Hi all, Its Aldo. anyways, I wont be using the method of pagination, i will just tell you how to
make a basic online now script. When someone logs in, now take into consideration that the name of
the username input is username ( First ,create a table in your database saying online now and add 2
fields to it. id and username CODE id type=integer(INT) , auto increment, length =255
and username = VARCHAR length=the limit a username should be in your site now from there we take
off : CODE <?php //logged.php //authentication script //connection scri....
Jsp Or Java Chat Script Like Mig33
(5) so most of you guys know mig33. its a wap application,probaly java.most kindly to be java. does
anyone have java knowlege or knows where i can get a chat script like mig33? i also know this server
supports jsp so im planing to use it for my application. i was hosted here last year but moved
because i found a better host. now im back just to use the jsp on this server. Im planing to run
chat applictions so if any one wants to help me in my project let me know.....
Working With Autistic Children
Developmentally Delayed Children (15) I have worked in the field of Special Education for twelve years. During the past five years, I
have seen a rise in the number of students entering into the public schools with the diagnosis of
Autism. Autism is a part of a spectrum of special education. Children can be very mild to the very
severe. Autistic children should not be feared. The key in helping a child with Autism is early
intervertion and a strong support system for the family. Public Schools across the country are now
offering developmentally delayed preschools. Children who show signs of delays in ....
Trap17 Link Exchange Script Introduced
(28) Hi, We have introduced a link Exchange Script at Trap17. http://www.addlivelinks.com/ The
categories are yet to be setup. It will be done as we receive link requests. Thanks. -OpaQue....
Watermark Your Image With Simple Php Script
found it on the net (35) This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
Scripts site. Just in case the site may not show, I will include the code here: List of things
needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
script below with name (i.e. watermark.php) CODE <?php // this script creates a watermarked
image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly
transparent gif image with the watermark - goes in the same directory as this script // ....
Slow Connection With Linksys Wrt54g Router
working fine until few months ago (8) Hey there everybody! I need some help. Here's the problem. I have a Linksys Wireless WRT54G
v5 router, which, I think, is acting up. First of all, I can't get port forwarding to work!
About three month ago my port forwarding was working flawlessly, I could use download clients like
DC++, or BitComet, or have an ftp server running, etc... Now, whichever ports I use, nothing seems
to work. Plus, in clients like DC++ where you're connected to several hubs, the connection to
the hubs is constantly dropped. On top of that, the joke's on me actually....
Verifying Email Addresses
Using a simple PHP script (9) This simple script will allow you to run some basic checks to make sure that any email address
entered is actually an email address. There is no guarantee offered that this will stop every single
fake email address, but it'll provide some protection. Now, the code! First we need to get
the email address to verify. Here, I get it using POST from an HTML form. CODE <?php //Load
email address from web form $email = $_POST['email']; Now, we move on
to our first check. Does the text that has been entered look like it could b....
Ipod Not Working, Need Help
(20) Not sure if this is the right forum, but I didn't see anywhere else for it... Ok, my girlfriend
got a 4 GB iPod Nano about a month ago. She had about 100 songs on it and one day they just
disappeared. Her normal PC won't recognize that she has the iPod plugged in, and her
stepdad's laptop will recognize it... But after she transfers all the songs, and she unplugs the
iPod from the laptop, she loses all of her songs again... She talked to an apple guy, but they said
she needed to do a system restore on it, but they didn't tell her how... And she can't ....
Problems With Outlook Express
My email configuration isn't working (7) Does anyone have a clue as to why my outgoing email isn't working with Outlook express? I can
get incoming mail, but I'm getting an error when I try to send email. I followed the
configuration instructions, but it still isn't working correctly. I get an error everytime.....
Delay X Seconds In Flash
how to action script that (1) How do i have to do, to tell a frame to wait x seconds after it continues playing? In Macromedia
Flash, of course... Like: CODE stop(); "wait x seconds"; play();
Thanks....
Guestbook (cgi-script) Problems
Do u know much bout chmod and cgi-cripts? (5) Hi! I'd like to make a guestbook with a cgi-script I found at Lissa Explains it All .
There were instruction bout how to install this gbook: click here QUOTE Active Guestbook
Unzip the file, you'll find 4 separate files: guestbook.cgi mail.gif url.gif readme.txt 1.
Open guestbook.cgi in a plain text editor like notepad. Find out your path to perl from your Web
host, and change the first line to reflect that. The default setting, #!/usr/bin/perl, usually
works for most servers. If not, you can try #!/usr/local/bin/perl. Save your changes. ....
Web Surfing- Script Needed
(2) We all know of anonymouse web surfing, Sites like http://anonymouse.ws/cgi-bin/anon-www.cgi Offer
peope to surf the internet anonymousely, The site has baners and ads showing up and does not support
all links. Does anyone know what script they use or where i could get one from, What script do they
use? Also if anyone jnows how to make my own? I really want this as a addon for my site, So all help
would be appriciated. Thanks, Mbd5882....
[help] Java Script: Window.open
Works with Firefox, not IE (10) CODE <HEAD> var popUpWin=0; function popUpWindow(URLStr) {
if(popUpWin) { if(!popUpWin.closed) popUpWin.close(); }
popUpWin = open(URLStr, 'GunBound Tactics: Screenshots',
'width=820,height=550,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,top=90,left=90')
;; } </HEAD> <BODY> <a
href="javascript:popUpWindow('/f11/clipped.php');"><b>Clips&
#60;/b></a> This is a script for opening a new window. It works ....
Many Php Script Sites
(16) Hi I find many sites has PHP scripts :: http://www.proxy2.de/scripts.php http://www.free-php.net
http://knubbe.t35.com/ http://www.ngcoders.com/ http://www.oxyscripts.com/
http://www.phparena.net/ http://www.1phpstreet.com/ http://px.sklar.com/
http://www.scoznet.com/ http://php.resourceindex.com/ /blink.gif' border='0'
style='vertical-align:middle' alt='blink.gif' /> ....
Sata Hard Drive Not Recognized By Windows
WD 250gb SATA hard drive not working (12) Hi there! I recently re-installed windows on my 250 gb WD SATA hard drive. I had a 50 gb
windows partition and the rest for files. First thing that happened was my system partition
wouldn't boot and eventually chkdsk said that the mbr was unrecoverable. A friend recommended
that i use a seperate parallel hard drive to load windows and then convert the disk to dynamic in
disk management. I did this, but the computer crashed and now windows won't even load with the
SATA hard drive connected. The BIOS sees the SATA hdd, but that's as far as I can get. I tri....
Looking for script, working,
|
*RANDOM STUFF*
*SIMILAR VIDEOS*
Searching Video's for script, working,
*MORE FROM TRAP17.COM*
|
advertisement
|
|