Strings str_starts_with
(PHP 8)
str_starts_with — 문자열이 주어진 부분 문자열로 시작하는지 확인
설명
str_starts_with(string $haystack
, string $needle
): bool
haystack
가 needle
로 시작하는지 여부를 나타내는 대소문자를 구분하는 검사를 수행합니다..
매개변수
haystack
- 검색할 문자열입니다.
needle
haystack
에서 검색할 하위 문자열입니다.
반환 값
haystack
가 needle
로 시작하면 true
를 반환하고 그렇지 않으면 false
를 반환합니다.
Examples
예제 #1 빈 문자열 '' 사용
<?php
if (str_starts_with('abc', '')) {
echo "All strings start with the empty string";
}
?>
위의 예는 다음을 출력합니다.
All strings start with the empty string
예제 #2 대소문자 구분 표시
<?php
$string = 'The lazy fox jumped over the fence';
if (str_starts_with($string, 'The')) {
echo "The string starts with 'The'\n";
}
if (str_starts_with($string, 'the')) {
echo 'The string starts with "the"';
} else {
echo '"the" was not found because the case does not match';
}
?>
위의 예는 다음을 출력합니다.
The string starts with 'The' "the" was not found because the case does not match
메모
참고: 이 함수는 binary-safe입니다.
기타
- str_contains() - 문자열에 주어진 부분 문자열이 포함되어 있는지 확인
- str_ends_with() - 문자열이 주어진 부분 문자열로 끝나는지 확인
- stripos() - 문자열에서 대소문자를 구분하지 않는 하위 문자열이 처음 나타나는 위치 찾기
- strrpos() - 문자열에서 하위 문자열이 마지막으로 나타나는 위치 찾기
- strripos() - 문자열에서 대소문자를 구분하지 않는 하위 문자열이 마지막으로 나타나는 위치 찾기
- strstr() - 문자열의 첫 번째 항목 찾기
- strpbrk() - 임의의 문자 집합에 대한 문자열 검색
- substr() - 문자열의 일부 반환
- preg_match() - 정규식 일치 수행