PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




PHP Count_Chars Function


Tutorials »Php »

Topic

What is count_Chars Function?



Explanation

In PHP, this function is used to return information about characters used in a string.

Syntax:
    count_chars(string,mode)

In the above syntax for the given "string" , mode has values "0,1,2,3,4"

MODE DESCRIPTION
"0" An array with the ASCII value as key and number of occurrences as value
"1" An array with the ASCII value as key and number of occurrences as value, only lists occurrences greater than zero
"2" An array with the ASCII value as key and number of occurrences as value, only lists occurrences equal to zero are listed
"3" A string with all the different characters used
"4" A string with all the unused characters
Example:
    <?php
    $str = "Hey how are you!";
    print_r(count_chars($str,1));
    ?>
Result:
    Array ( 
     [32] => 3 
     [33] => 1 
     [72] => 1 
     [97] => 1 
     [101] => 2 
     [104] => 1 
     [111] => 2 
     [114] => 1 
     [117] => 1 
     [119] => 1 
     [121] => 2 
     ) 

In the above example the string "$str" is displayed as an array with ASCII as the key and number of occurences as values.





A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting