substr_count - 하위 문자열 항목 수를 센다. 정보
PHP substr_count - 하위 문자열 항목 수를 센다.본문
substr_count - 하위 문자열 항목 수를 센다.
설명 ¶
int substr_count ( string $haystack , string $needle [, int $offset= 0 [, int $length ]])
substr_count () 는needle문자열에서부분 문자열이 발생 하는 횟수를 반환 haystack합니다. needle대소 문자를 구분하므로주의하십시오 .
참고 :
이 함수는 중복 된 하위 문자열을 계산하지 않습니다. 아래 예제를 참조하십시오!
매개 변수 ¶
haystack
검색 할 문자열
needle
검색 할 하위 문자열
offset
카운팅을 시작할 위치 오프셋입니다. 오프셋이 음수이면 문자열 끝에서부터 계산이 시작됩니다.
length
하위 문자열을 검색 할 지정된 오프셋 뒤의 최대 길이입니다. 오프셋과 길이가 길이보다 큰 경우 경고를 출력합니다 haystack. 음수 길이는의 끝에서부터 계산됩니다 haystack.
반환 값 ¶
이 함수는 정수를 반환합니다 .
예 ¶
Example # 1 substr_count () 예제
<?php
$text = 'This is a test';
echo strlen($text); // 14
echo substr_count($text, 'is'); // 2
// the string is reduced to 's is a test', so it prints 1
echo substr_count($text, 'is', 3);
// the text is reduced to 's i', so it prints 0
echo substr_count($text, 'is', 3, 3);
// generates a warning because 5+10 > 14
echo substr_count($text, 'is', 5, 10);
// prints only 1, because it doesn't count overlapped substrings
$text2 = 'gcdgcdgcd';
echo substr_count($text2, 'gcdgcd');
?>
0
댓글 0개