PHP str_pad() Fungsi
Contoh
Pad ke sisi kanan string, dengan panjang baru 20 karakter:
<?php
$str = "Hello World";
echo str_pad($str,20,".");
?>
Definisi dan Penggunaan
Fungsi str_pad() memasukkan string ke panjang baru.
Sintaksis
str_pad(string,length,pad_string,pad_type)
Nilai Parameter
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:
|
Detail Teknis
Nilai Kembali: | Mengembalikan string empuk |
---|---|
Versi PHP: | 4.0.1+ |
Lebih Banyak Contoh
Contoh
Pad ke sisi kiri string:
<?php
$str = "Hello World";
echo str_pad($str,20,".",STR_PAD_LEFT);
?>
Contoh
Pad ke kedua sisi string:
<?php
$str = "Hello World";
echo str_pad($str,20,".:",STR_PAD_BOTH);
?>
Referensi String PHP