PHP str_pad() Functie
❮ Referentie voor PHP-tekenreeksen
Voorbeeld
Pad naar de rechterkant van de tekenreeks, tot een nieuwe lengte van 20 tekens:
<?php
$str = "Hello World";
echo str_pad($str,20,".");
?>
Definitie en gebruik
De functie str_pad() vult een string op naar een nieuwe lengte.
Syntaxis
str_pad(string,length,pad_string,pad_type)
Parameterwaarden
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:
|
Technische details
Winstwaarde: | Retourneert de gewatteerde string |
---|---|
PHP-versie: | 4.0.1+ |
Meer voorbeelden
Voorbeeld
Pad aan de linkerkant van de string:
<?php
$str = "Hello World";
echo str_pad($str,20,".",STR_PAD_LEFT);
?>
Voorbeeld
Pad aan beide zijden van de snaar:
<?php
$str = "Hello World";
echo str_pad($str,20,".:",STR_PAD_BOTH);
?>
❮ Referentie voor PHP-tekenreeksen