str_pad --- 填塞字串成為指定的長度
語法 : string str_pad (string input, int pad_length [, string pad_string [, int pad_type]])
說明 :
此函式填塞到字串參數 input的左邊、右邊或是左邊及右邊,成為指定的填塞長度。如果沒有提供非必需選項 pad_string,則使用空白將參數 input填塞,否則,它會使用 pad_string填塞到指定的長度。
非必需選項 pad_type可以是STR_PAD_RIGHT、STR_PAD_LEFT或是STR_PAD_BOTH,如果沒有指定 pad_type,則假定為 STR_PAD_RIGHT。
如果 pad_length的值是負數或是小於輸入字串的長度時,則不會填塞。
Example :
<?php
$input = "Alien";
print str_pad($input, 10); // produces "Alien "
print str_pad($input, 10, "-=", STR_PAD_LEFT); // produces "-=-=-Alien"
print str_pad($input, 10, "_", STR_PAD_BOTH); // produces "__Alien___"
?>