PHP strcspn() 함수
예시
"Hello world!"에서 찾은 문자 수를 출력하십시오. 문자 "w" 앞:
<?php
echo strcspn("Hello world!","w");
?>
정의 및 사용
strcspn() 함수는 지정된 문자의 일부를 찾기 전에 문자열에서 찾은 문자 수(공백 포함)를 반환합니다.
팁: strspn() 함수를 지정된 문자 목록의 문자만 포함하는 문자열에서 찾은 문자 수에 사용 하십시오.
참고: 이 함수는 바이너리 안전합니다.
통사론
strcspn(string,char,start,length)
매개변수 값
Parameter | Description |
---|---|
string | Required. Specifies the string to search |
char | Required. Specifies the characters to search for |
start | Optional. Specifies where in string to start |
length | Optional. Specifies the length of the string (how much of the string to search) |
기술적 세부 사항
반환 값: | 지정된 문자의 일부를 찾기 전에 문자열에서 찾은 문자 수를 반환합니다. |
---|---|
PHP 버전: | 4+ |
변경 로그: | PHP 4.3에 시작 및 길이 매개변수가 추가되었습니다 . |
더 많은 예
예시
모든 매개변수를 사용하여 "Hello world!"에서 찾은 문자 수 인쇄 문자 "w" 앞:
<?php
echo strcspn("Hello world!","w",0,6); // The start position is 0 and the length of the search string is 6.
?>
❮ PHP 문자열 참조