substr_count 함수

함수 substr_count는 문자열에서 부분 문자열이 몇 번 나타나는지 계산합니다. 라틴 문자(싱글바이트 문자)에서만 정확하게 작동합니다.

구문

phpsubstr_count(string $haystack, string $needle, int $offset = 0, ?int $length = null): int

예제

문자열에서 부분 문자열 'test'가 몇 번 나타나는지 계산해 봅시다:

php<?php
  echo substr_count('test www test', 'test');  
?>

코드 실행 결과:

php2

참고 항목