Strings rtrim
(PHP 4, PHP 5, PHP 7, PHP 8)
rtrim — 문자열 끝에서 공백(또는 다른 문자) 제거
설명
rtrim(string $string
, string $characters
= " \n\r\t\v\x00"): string
이 함수는 string
끝에서 공백(또는 다른 문자)이 제거된 문자열을 반환합니다.
두 번째 매개변수가 없으면 rtrim()은 다음 문자를 제거합니다.
- " " (ASCII
32
(0x20
)), an ordinary space. - "\t" (ASCII
9
(0x09
)), a tab. - "\n" (ASCII
10
(0x0A
)), a new line (line feed). - "\r" (ASCII
13
(0x0D
)), a carriage return. - "\0" (ASCII
0
(0x00
)), theNULL
-byte. - "\v" (ASCII
11
(0x0B
)), a vertical tab.
매개변수
string
- 입력 문자열입니다.
characters
characters
매개변수를 사용하여 제거할 문자를 지정할 수도 있습니다. 제거하려는 모든 문자를 나열하기만 하면 됩니다. ..를 사용하여 문자 범위를 지정할 수 있습니다.
반환 값
수정된 문자열을 반환합니다.
Examples
예제 #1 rtrim()의 사용 예제
<?php
$text = "\t\tThese are a few words :) ... ";
$binary = "\x09Example string\x0A";
$hello = "Hello World";
var_dump($text, $binary, $hello);
print "\n";
$trimmed = rtrim($text);
var_dump($trimmed);
$trimmed = rtrim($text, " \t.");
var_dump($trimmed);
$trimmed = rtrim($hello, "Hdle");
var_dump($trimmed);
// trim the ASCII control characters at the end of $binary
// (from 0 to 31 inclusive)
$clean = rtrim($binary, "\x00..\x1F");
var_dump($clean);
?>
위의 예는 다음을 출력합니다.
string(32) " These are a few words :) ... " string(16) " Example string " string(11) "Hello World" string(30) " These are a few words :) ..." string(26) " These are a few words :)" string(9) "Hello Wor" string(15) " Example string"