nonexist Posted October 24, 2008 Share Posted October 24, 2008 Hello. I have a script that make a repetative permutation. Because of the size of the output the script can over do PHP's memory limit. <? function permutations($letters,$num){ $last = str_repeat($letters{0},$num); $result = array(); while($last != str_repeat(lastchar($letters),$num)){ $result[] = $last; $last = char_add($letters,$last,$num-1); } $result[] = $last; return $result; } function char_add($digits,$string,$char){ if($string{$char} <> lastchar($digits)){ $string{$char} = $digits{strpos($digits,$string{$char})+1}; return $string; }else{ $string = changeall($string,$digits{0},$char); return char_add($digits,$string,$char-1); } } function lastchar($string){ return $string{strlen($string)-1}; } function changeall($string,$char,$start = 0,$end = 0){ if($end == 0) $end = strlen($string)-1; for($i=$start;$i<=$end;$i++){ $string{$i} = $char; } return $string; } ?> Working Now... <? mysql_connect("localhost","root","pass"); mysql_select_db("DB"); $ts = 1; $tt = 3; $a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*?"; $myFile = "file"; $fh = fopen($myFile, 'w') or die("can't open file"); $phpInsertOpen = "<?PHP "; fwrite($fh, $phpInsertOpen); $myInsert = "\$xA = array("; fwrite($fh, $myInsert); while($ts < $tt){ $Array=permutations($a,$ts); for($i=0 ; $i < count($Array) ; $i++) { if($Array[$i] == "a"){ fwrite($fh,"\"$Array[$i]\""); } else { fwrite($fh,", \"$Array[$i]\""); } } $ts++; } $insertClose = ");"; fwrite($fh, $insertClose); $phpInsertClose = "?>"; fwrite($fh, $phpInsertClose); fclose($fh); ?> I have it where the length can be controlled by the smallest length of characters to start with, and the number to end with. I am wondering if there is a way to fix it where, like lets say I want 4-4.5, then it would do half of the output as compared to 4-5. This is the only way I could think of it. Or if before the script over does the memory, it reloads the page and starts from where it left off ??? I not to sure how you would do this, but then again theres alot of things I dont know :-\ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.