دالة 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