...

View Full Version : Odd Array



Deacon Frost
01-16-2009, 04:22 AM
Ok, I need a script that takes an string of characters, changes it, adds it to an array, and then echoes it.

I can't do it in Javascript, because I don't want the users to see how it's done.

So here are some possible ways of doing it:

1. Is to have the button, and input field for the string. User inputs their string, clicks the button. PHP takes it, changes it a set number of times, and outputs every result on the new page.

while($setnumberoftimes <= $numberoftimes)){ echo $result . "/n" }

I figured something like that would be my best bet?

2. A database. I'd rather not take this route, but I do admit its possibility.

3. Last but not least, if it won't happen, I can go back to doing javascript. Lol. It has to be hidden from the users though, I don't want them seeing the technique which I use to create the multiple strings.


This really shouldn't stump me, as I know it's super easy to do =/.

funnymoney
01-16-2009, 07:14 AM
<?php

$string = "abcde";

$chars = strlen($string);

$string_array = array();
$i = 0;
while ($i < $chars) {
$string_array[$i]=$string[$i];
$i++;
}
print_r ($string_array);


?>

zomething likez thiz?

Deacon Frost
01-16-2009, 02:14 PM
Er, that works, somewhat, but I still need a lot of stuff added to it. I rarely work with arrays, but this would seem like the best way to do it?

So say I have this:



<?php

function createRandomPassword() {



$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";

srand((double)microtime()*1000000);

$i = 0;

$pass = '' ;



while ($i <= 7) {

$num = rand() % 33;

$tmp = substr($chars, $num, 1);

$pass = $pass . $tmp;

$i++;

}



return $pass;



}



// Usage
for ( $counter = 10; $counter <= 100; $counter += 10) {
$password = createRandomPassword();
}
do {
echo "Your random password is: " . $password . "<br />";
}
while($counter = 10; $counter <= 100; $counter += 10)
$ip=$_SERVER['REMOTE_ADDR'];
$File = $ip . ".txt";
$Handle = fopen($File, 'w+');
$Data = $password
fwrite($Handle, $Data);
print "Data Written";
fclose($Handle);


?>



How would I make it work?


It's on refresh right now. I'd just change the values and such to be variables, and add user input, but that part is easy.

funnymoney
01-16-2009, 06:00 PM
Sorry, but i don't follow :(

Deacon Frost
01-16-2009, 06:37 PM
I've got it basically working ^.^. I just have to add functionality.


I made it so it writes to a file, and goes by IP address. I'll probably end up using a database... but..

http://ispikedthepunch.com/emailgen/emails.php just so you understand ^.^.

funnymoney
01-16-2009, 08:49 PM
ok mate, glad you made it :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum