auto increasing id
<p>I would like to build a php script that automatically generates a new id by increasing the previous by 1.
eg: A0009 becomes A0010 and A9999 becomes B0000</p>

<p>I have written one that works but it doesn't go over 5 chars long:
eg: Z9999 should go to A00000 and so on.</p>

<p>Any suggestions? 
here is my snippet:</p>

<pre><code>&lt;?php
function replaceChar($string2replace)
{
$charLength = strlen($string2replace)-1;
$charAt = array();
$charAt[4] = substr($string2replace, -1);
$charAt[3] = substr($string2replace, -2,1);
$charAt[2] = substr($string2replace, -3,1);
$charAt[1] = substr($string2replace, -4,1);
$charAt[0] = substr($string2replace, 0,1);

if($charAt[4] &lt; 9)
{
$string2replace = substr_replace($string2replace,$charAt[4]+1,$charLength);
}
else
{
$charAt[4] = 0;
$string2replace = substr_replace($string2replace,$charAt[4],$charLength);
    if($charAt[3] &lt; 9)
{
$string2replace = substr_replace($string2replace,$charAt[3]+1,$charLength- 1,1);
}
else
{
$charAt[3] = 0;
$string2replace = substr_replace($string2replace,$charAt[3],$charLength-1,1);

if($charAt[2] &lt; 9)
{
$string2replace =  substr_replace($string2replace,$charAt[2]+1,$charLength-2,1);
}
else
{
$charAt[2] = 0;
$string2replace = substr_replace($string2replace,$charAt[2],$charLength-2,1);

if($charAt[1] &lt; 9)
{
$string2replace = substr_replace($string2replace,$charAt[1]+1,$charLength-3,1);
}
else
{
$charAt[1] = 0;
    $string2replace =    substr_replace($string2replace,$charAt[1],$charLength-3,1);
    }

if($charAt[0] &lt; 'z')
{
$charAt[0] ++;
$string2replace =    substr_replace($string2replace,$charAt[0],$charLength-4,1);
}
else
{
$charAt[0] = 'a';
$string2replace =  substr_replace($string2replace,$charAt[0],$charLength-4,1);
}
}   
}
}
return $string2replace;
}

$string2begin = 'A9999';

$generatedString = replaceChar($string2begin);

echo $string2begin . "&lt;br /&gt;" . $generatedString;


?&gt;
</code></pre>
