Page 1 sur 1

evolutive script with php

Posté : 29 avr. 2014, 22:50
par yassir gourram
I have been trying to improve this script in PHP so it can give me the value of a to 9999999999.....9999999999 (up to 72 characters) to insert in MySQL. So far it stops at 999. I have increased Apache's memory and the script exuction time but it still stays the same. Here is my script: "This code sets the value of a to 999."

<?php
function evol($length = 1, $deb_chaine = '') {
    $tab=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9");
    $str = '';
    if(strlen($deb_chaine) <= ($length - 1)) { 
    foreach($tab as $lettre) { 
        $str .= ' '. $deb_chaine . $lettre;
    }
    if($deb_chaine == '') { 
        $str .= evol($length, 'a');
    }
    else { // sinon
        $last = substr($deb_chaine, -1);
        $reste = substr($deb_chaine, 0, -1);
        if($last == "9") { 
        $i = strlen($deb_chaine) - 1;
        $reste = "";
        while($i >= 0) {
            if($deb_chaine[$i] == "9") {
            $reste = 'a'. $reste;
            }
            else { 
            $reste = $tab[(array_search($deb_chaine[$i], $tab) + 1)] . substr($reste, 0, -1);
            break 1;
            }
            $i--;
        }
        $new = 'a'; 
        }
        else { 
        $new = $tab[(array_search($last, $tab) + 1)];
        }
        $str .= evol($length, ($reste . $new)); 
    }
    }
    return $str;
}
echo evol(72);
?>