記法
書式
str_pad(対象文字列,埋める桁数,埋める文字列,埋める辺)
第一引数:0埋めの対象となる文字列
第二引数:埋める桁数
第三引数:埋める文字
第四引数:左を埋める場合はSTR_PAD_LEFT、右を埋める場合はSTR_PAD_RIGHT、両側を埋める場合はSTR_PAD_BOTHを指定します。実際にコードを書くとなると下記のようになります。
サンプルコード
Sample.php
$CountOfFiles=100;
for($i=1;$i<$CountOfFiles;$i++){
echo str_pad($i, 2, 0, STR_PAD_LEFT);
}
結果
結果
$ sample.php
001
002
003
004
...