Here's a function I always use for this if i'm not using mysql. $fNum is the number you want to fill with zeros, and $fDigits is the total number of digits you want.
function zerofill($fNum, $fDigits)
{
$fOutput = str_pad($fNum, $fDigits, "0", STR_PAD_LEFT);
return $fOutput;
}
So
echo zerofill(14, 3);
would output 014