add zeros to number or string
function addZeros($numcount, $value, $where) { if ($value=="") echo "Error: value is missing"; if ($numcount=="") echo "Error: numcount is missing"; $newnum = ""; $n = strlen($value); if ($where==">") $newnum .= $value; for ($i=0; $i<($numcount-$n); $i++) { $newnum .= "0"; } if ($where=="<") $newnum .= $value; return $newnum; } // usage: echo addZeros(8, "122", "<"); // echos 00000122 echo addZeros(5, "2", ">"); // echos 200000