trim — 문자열의 시작과 끝에서 공백 (또는 다른 문자)을 제거하십시오. 정보
PHP trim — 문자열의 시작과 끝에서 공백 (또는 다른 문자)을 제거하십시오.본문
trim — 문자열의 시작과 끝에서 공백 (또는 다른 문자)을 제거하십시오.
설명 ¶
string trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] )
이 함수는 str의 시작과 끝에서 공백을 제거한 문자열을 반환합니다.
두 번째 매개 변수가 없으면 trim ()은 다음 문자를 제거합니다.
" " (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)), the NUL-byte.
"\x0B" (ASCII 11 (0x0B)), a vertical tab.
인수 ¶
str
The string that will be trimmed.
character_mask
선택적으로, 제거 된 문자는 character_mask 매개 변수를 사용하여 지정할 수도 있습니다. 박탈하려는 모든 문자를 나열하십시오. ..로 문자 범위를 지정할 수 있습니다.
반환값 ¶
The trimmed string.
예제 ¶
Example #1 Usage example of trim()
<?php
$text = "\t\tThese are a few words :) ... ";
$binary = "\x09Example string\x0A";
$hello = "Hello World";
var_dump($text, $binary, $hello);
print "\n";
$trimmed = trim($text);
var_dump($trimmed);
$trimmed = trim($text, " \t.");
var_dump($trimmed);
$trimmed = trim($hello, "Hdle");
var_dump($trimmed);
$trimmed = trim($hello, 'HdWr');
var_dump($trimmed);
$clean = trim($binary, "\x00..\x1F");
var_dump($clean);
?>
위 예제의 출력:
string(32) " These are a few words :) ... "
string(16) " Example string
"
string(11) "Hello World"
string(28) "These are a few words :) ..."
string(24) "These are a few words :)"
string(5) "o Wor"
string(9) "ello Worl"
string(14) "Example string"
0
댓글 0개