DBからのものである場合、これはSQLクエリでそれを行う方法です。
lpad(yourfield, (select length(max(yourfield)) FROM yourtable),'0') yourfield
これにより、テーブルの最大値が取得され、先行ゼロが配置されます。
ハードコーディングされている場合(PHP)、str_pad()を使用します
str_pad($yourvar, $numberofzeros, "0", STR_PAD_LEFT);
これは私がオンラインのphpコンパイラで行ったことの小さな例であり、動作します...
$string = "Tutorial 1 how to";
$number = explode(" ", $string); //Divides the string in a array
$number = $number[1]; //The number is in the position 1 in the array, so this will be number variable
$str = ""; //The final number
if($number<10) $str .= "0"; //If the number is below 10, it will add a leading zero
$str .= $number; //Then, add the number
$string = str_replace($number, $str, $string); //Then, replace the old number with the new one on the string
echo $string;