String 함수 목록
PHP Manual

count_chars

(PHP 4, PHP 5)

count_chars문자열 안에 사용한 문자에 대한 정보를 반환

설명

mixed count_chars ( string $string [, int $mode ] )

string 안에서 모든 바이트 값(0..255)의 수를 세고 여러 방법으로 반환합니다.

인수

string

검사할 문자열.

mode

선택적인 인수 mode 의 기본값은 0입니다.

반환값

mode 에 따른 count_chars()의 반환값은 다음과 같습니다:

예제

Example #1 count_chars() 예제

<?php
$data 
"Two Ts and one F.";

foreach (
count_chars($data1) as $i => $val) {
   echo 
"There were $val instance(s) of \"" chr($i) , "\" in the string.\n";
}
?>

위 예제의 출력:

There were 4 instance(s) of " " in the string.
There were 1 instance(s) of "." in the string.
There were 1 instance(s) of "F" in the string.
There were 2 instance(s) of "T" in the string.
There were 1 instance(s) of "a" in the string.
There were 1 instance(s) of "d" in the string.
There were 1 instance(s) of "e" in the string.
There were 2 instance(s) of "n" in the string.
There were 2 instance(s) of "o" in the string.
There were 1 instance(s) of "s" in the string.
There were 1 instance(s) of "w" in the string.

참고


String 함수 목록
PHP Manual