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
https://forums.phpfreaks.com/topic/129888-help-with-output-of-a-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.