PHP str_pad()ฟังก์ชัน
ตัวอย่าง
แป้นทางด้านขวาของสตริง ให้มีความยาวใหม่ 20 อักขระ:
<?php
$str = "Hello World";
echo str_pad($str,20,".");
?>
ความหมายและการใช้งาน
ฟังก์ชัน str_pad() แพดสตริงเป็นความยาวใหม่
ไวยากรณ์
str_pad(string,length,pad_string,pad_type)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
string | Required. Specifies the string to pad |
length | Required. Specifies the new string length. If this value is less than the original length of the string, nothing will be done |
pad_string | Optional. Specifies the string to use for padding. Default is whitespace |
pad_type | Optional. Specifies what side to pad the string. Possible values:
|
รายละเอียดทางเทคนิค
คืนมูลค่า: | ส่งกลับสตริงเบาะ |
---|---|
รุ่น PHP: | 4.0.1+ |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
แป้นทางด้านซ้ายของสตริง:
<?php
$str = "Hello World";
echo str_pad($str,20,".",STR_PAD_LEFT);
?>
ตัวอย่าง
ปาดไปทั้งสองด้านของสายอักขระ:
<?php
$str = "Hello World";
echo str_pad($str,20,".:",STR_PAD_BOTH);
?>
❮ การอ้างอิงสตริง PHP