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 문자열 참조