string str_pad ( string $input
, int $pad_length
[, string $pad_string
= " " [, int $pad_type
= STR_PAD_RIGHT ]] )
$input= 來源字串
$pad_length= 要補到幾個字
$pad_string=要補什麼字
$pad_type=從哪裡開始補 1.左右都補:STR_PAD_BOTH ,2.由左邊開始補:STR_PAD_LEFT , 3.由右邊開始補:STR_PAD_RIGHT
1 |
<span id="lnum1" style="color: #606060;"> 1:</span> <span style="color: #008000;">//要把ID 由左邊開始補0 ,補到5位數</span> |
1 |
<span id="lnum2" style="color: #606060;"> 2:</span> $id=01; |
1 |
<span id="lnum3" style="color: #606060;"> 3:</span> $id=str_pad($id,5,<span style="color: #006080;">"0"</span>,STR_PAD_LEFT); |
1 |
<span id="lnum4" style="color: #606060;"> 4:</span> <span style="color: #0000ff;">echo</span> $id; |
1 |
<span id="lnum5" style="color: #606060;"> 5:</span> <span style="color: #008000;">//00001</span> |
(Visited 51 times, 1 visits today)