Jump to content

Text feild variables!


pyro.699
 Share

Recommended Posts

ok, i made a text feild

<input tabindex="1" name="A" type="text" value="XXXX" size="7" maxlength="4" />

and what i want to do as add each character in the "text feild" to a variable,since default it XXXX i would like the out put to be something like this$first = X;$second = X;$third = X;$fourth = X;like each digit a separate variable.it goes from A - F so 48ish variables would be put out....(its not always going to be 4x X's)

Link to comment
Share on other sites

it did! thanks!since this is a validator, i need to find a fast was to add numbers up :)i need four numbers that equals, lets say, 50example: 23 + 2 + 12 + 13 = 50is there a quick code i could use to find EVERY posible equation, the highest posible number being 26...(dont worry, img going to have more securety than just this :))

Link to comment
Share on other sites

it did! thanks!since this is a validator, i need to find a fast was to add numbers up :)i need four numbers that equals, lets say, 50example: 23 + 2 + 12 + 13 = 50is there a quick code i could use to find EVERY posible equation, the highest posible number being 26...(dont worry, img going to have more securety than just this :))

You could do something like:
if($var_array[0]+$var_array[1]+$var_array[2]+$var_array[3]==50){//Code for if the numbers equal 50.}

Or, if you don't know how many indices in the array there are,

$sum = 0;foreach($var_array as $key=>$value){$sum += $value;}if($sum == 50){//Code for if the numbers equal 50.}

I think that should work...

Link to comment
Share on other sites

this isent going to be part of the code, i need something to spit out all the posibilities, lol.. cause i need to write / print them off... something simplelike this would be the page-------------------------------|5+3+1+7|2+4+6+2|...|..|.|||||listing every posibility :)

Link to comment
Share on other sites

Oh, I see. That would be a little bit more complex. :)Well, I guess you could do this:

<?php	for($num1=1; $num1<=26; $num1++){  for($num2=1; $num2<=26; $num2++){ 	 for($num3=1; $num3<=26; $num3++){    for($num4=1; $num4<=26; $num4++){   	 if($num1+$num2+$num3+$num4 == 50){      echo $num1.' + '.$num2.' + '.$num3.' + '.$num4."<br />\n";   	 }    } 	 }  }	}?>

I have to warn you though, that it will output 456976 lines...It could actually be modified to remove any such as 18 + 22 + 4 + 6 where there's already 22 + 6 + 4 + 18 and so on.

Link to comment
Share on other sites

Oh, I see. That would be a little bit more complex. :)Well, I guess you could do this:
<?php	for($num1=1; $num1<=26; $num1++){  for($num2=1; $num2<=26; $num2++){ 	 for($num3=1; $num3<=26; $num3++){    for($num4=1; $num4<=26; $num4++){   	 if($num1+$num2+$num3+$num4 == 50){      echo $num1.' + '.$num2.' + '.$num3.' + '.$num4."<br />\n";   	 }    } 	 }  }	}?>

I have to warn you though, that it will output 456976 lines...

oh, dont worry, ive... closed every program, (encluding windows stuff, i dont have music anymore :( just for this :))to change the numebr that it equals to, just chanfe == 50?anyway to get rid of doubles?like 1+1+22+2626+22+1+1
Link to comment
Share on other sites

Then you change it to

<?php	for($num1=1; $num1<=26; $num1++){  for($num2=1; $num2<=26; $num2++){ 	 for($num3=1; $num3<=26; $num3++){    for($num4=1; $num4<=26; $num4++){   	 if($num1-$num2+$num3-$num4 == 50){      echo $num1.' - '.$num2.' + '.$num3.' - '.$num4."<br />\n";   	 }    } 	 }  }	}?>

Also, I've almost figured out how to do the repeat checking, it'll just take a couple minutes. :)Edit:Alright, this code will check to make sure there are no duplicates, in any order:

<?php	$i = 0;	$donearray = array();	for($num1=1; $num1<=26; $num1++){  for($num2=1; $num2<=26; $num2++){ 	 for($num3=1; $num3<=26; $num3++){    for($num4=1; $num4<=26; $num4++){   	 if($num1+$num2+$num3+$num4 == 50){      if( in_array($num1.' + '.$num2.' + '.$num3.' + '.$num4."<br>\n", $donearray) == false &&      	 in_array($num2.' + '.$num3.' + '.$num4.' + '.$num1."<br>\n", $donearray) == false &&     	 in_array($num3.' + '.$num4.' + '.$num1.' + '.$num2."<br>\n", $donearray) == false &&     	 in_array($num4.' + '.$num1.' + '.$num2.' + '.$num3."<br>\n", $donearray) == false &&     	 in_array($num1.' + '.$num2.' + '.$num4.' + '.$num3."<br>\n", $donearray) == false &&     	 in_array($num2.' + '.$num4.' + '.$num3.' + '.$num1."<br>\n", $donearray) == false &&     	 in_array($num4.' + '.$num3.' + '.$num1.' + '.$num2."<br>\n", $donearray) == false &&     	 in_array($num3.' + '.$num1.' + '.$num2.' + '.$num4."<br>\n", $donearray) == false &&     	 in_array($num1.' + '.$num4.' + '.$num3.' + '.$num2."<br>\n", $donearray) == false &&     	 in_array($num4.' + '.$num3.' + '.$num2.' + '.$num1."<br>\n", $donearray) == false &&     	 in_array($num3.' + '.$num2.' + '.$num1.' + '.$num4."<br>\n", $donearray) == false &&     	 in_array($num2.' + '.$num1.' + '.$num4.' + '.$num3."<br>\n", $donearray) == false &&     	 in_array($num1.' + '.$num3.' + '.$num2.' + '.$num4."<br>\n", $donearray) == false &&     	 in_array($num3.' + '.$num2.' + '.$num4.' + '.$num1."<br>\n", $donearray) == false &&     	 in_array($num2.' + '.$num4.' + '.$num1.' + '.$num3."<br>\n", $donearray) == false &&     	 in_array($num4.' + '.$num1.' + '.$num3.' + '.$num2."<br>\n", $donearray) == false &&     	 in_array($num4.' + '.$num2.' + '.$num3.' + '.$num1."<br>\n", $donearray) == false &&     	 in_array($num2.' + '.$num3.' + '.$num1.' + '.$num4."<br>\n", $donearray) == false &&     	 in_array($num3.' + '.$num1.' + '.$num4.' + '.$num2."<br>\n", $donearray) == false &&     	 in_array($num1.' + '.$num4.' + '.$num2.' + '.$num3."<br>\n", $donearray) == false &&     	 in_array($num3.' + '.$num2.' + '.$num1.' + '.$num4."<br>\n", $donearray) == false &&     	 in_array($num2.' + '.$num1.' + '.$num4.' + '.$num3."<br>\n", $donearray) == false &&     	 in_array($num1.' + '.$num4.' + '.$num3.' + '.$num2."<br>\n", $donearray) == false &&     	 in_array($num4.' + '.$num3.' + '.$num2.' + '.$num1."<br>\n", $donearray) == false &&     	 in_array($num2.' + '.$num1.' + '.$num3.' + '.$num4."<br>\n", $donearray) == false &&     	 in_array($num1.' + '.$num3.' + '.$num4.' + '.$num2."<br>\n", $donearray) == false &&     	 in_array($num3.' + '.$num4.' + '.$num2.' + '.$num1."<br>\n", $donearray) == false &&     	 in_array($num4.' + '.$num2.' + '.$num1.' + '.$num3."<br>\n", $donearray) == false){        $donearray[$i]=$num1.' + '.$num2.' + '.$num3.' + '.$num4."<br>\n";        echo $donearray[$i];        $i++;      }   	 }    } 	 }  }	}?>

See why it took me a while?There must be an easier way...

Link to comment
Share on other sites

!yeah! nice! thanks!lol :( i got a new challange for ya, arnt i testing your skillz 2day :Di have 6 filesFile #1 has 1798 linesFile #2 has 1842 linesFile #3 has 1747 linesFile #4 has 2265 linesFile #5 has 2137 linesFile #6 has 2197 linesnow, i was wondering if you could make a script that would "explode" them all to a file, again, giving every posible combonation ( i used your script, and chopped it up a little(the replys))idk if it hepls but the file names arefirst.combosecond.combothird.combofourth.combofifth.combosixth.combo(i even made a special icon for all .combo files :))(again, deleting all posible duplicates :))(every line contains a code, again 4 chars, like AHFW would be line 435. )

Link to comment
Share on other sites

(you dont need to keep adding to that file :)) Make a new one, im gona print this 1 after i get it :(...Ok, ill me a bit more presiceFile #1 - ASDGFile #2 - WBNXFile #3 - FIFKFile #4 - GJHRFile #5 - EGSTFile #6 - SDHGthe script would combine those to makeASDG - WBNX - FIFK - GJHR - EGST - SDGH(there is more than one code in each file :)) but it dose the same thing as it did with the numbers except its dealing with files, and not numbers letters, and 4 of them... and 6 files...

Link to comment
Share on other sites

I know, and thats fine, the only problem is that checking 6 variables is exponentially longer than checking for variables (For duplicates) in server time and writing time.Right now, as you can see, it check four variables in groups of four. With six variables, it would have to check them in groups of six, and there would be more groups as well.So, this will combine the six variables, but it doesn't do any duplicate checking yet.Also, what do you want to happen when it runs ot of lines in one of the files?

<?php	$code1 = file('first.combo');	$code2 = file('second.combo');	$code3 = file('third.combo');	$code4 = file('fourth.combo');	$code5 = file('fifth.combo');	$code6 = file('sixth.combo');	$total = count($code1)+count($code2)+count($code3)+count($code4)+count($code5)+count($code6);	for($i=0; $i<=$total; $i++){  $output = $code1[$i].' - '.$code2[$i].' - '.$code3[$i].' - '.$code4[$i].' - '.$code5[$i].' - '.$code6[$i]."<br>\n";	}?>

Link to comment
Share on other sites

As it is, when one ends I'm not really sure what will happen, but I think it will error.This script is slightly better:

  <?php 	 $code1 = file('first.combo'); 	 $code2 = file('second.combo'); 	 $code3 = file('third.combo'); 	 $code4 = file('fourth.combo'); 	 $code5 = file('fifth.combo'); 	 $code6 = file('sixth.combo'); 	 $total = count($code1)+count($code2)+count($code3)+count($code4)+count($code5)+count($code6); 	 $totaleach = array(count($code1),count($code2),count($code3),count($code4),count($code5),count($code6)); 	 sort($totaleach); 	 for($i=0; $i<=$totaleach[5]; $i++){    $output[] = $code1[$i].' - '.$code2[$i].' - '.$code3[$i].' - '.$code4[$i].' - '.$code5[$i].' - '.$code6[$i]."<br>\n"; 	 }  ?>

You should see what happens when you run it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...