PHP str_pad() İşlev
Örnek
Dizenin sağ tarafına 20 karakterlik yeni bir uzunluğa getirin:
<?php
$str = "Hello World";
echo str_pad($str,20,".");
?>
Tanım ve Kullanım
str_pad() işlevi, bir dizgiyi yeni bir uzunluğa doldurur.
Sözdizimi
str_pad(string,length,pad_string,pad_type)
Parametre Değerleri
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:
|
Teknik detaylar
Geri dönüş değeri: | yastıklı dizeyi döndürür |
---|---|
PHP Sürümü: | 4.0.1+ |
Daha fazla örnek
Örnek
Dizenin sol tarafına ped:
<?php
$str = "Hello World";
echo str_pad($str,20,".",STR_PAD_LEFT);
?>
Örnek
Dizenin her iki tarafına ped:
<?php
$str = "Hello World";
echo str_pad($str,20,".:",STR_PAD_BOTH);
?>
❮ PHP Dize Referansı