Jump to content

Help with output of a script.


nonexist

Recommended Posts

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  :-\

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.