PHP count_chars() Function
Complete PHP String Reference
Definition and Usage
The count_chars() function returns how many times an ASCII character occurs
within a string and returns the information.
Syntax
| Parameter |
Description |
| string |
Required. The string to be checked |
| mode |
Optional. Specifies the return modes.
0 is default. The different return modes are:
- 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 1
In this example we will use count_char() with mode 1 to check the string.
Mode 1 will return an array with the ASCII value as key and how
many times it occurred as value (e.g. in the example below, the ASCII value for
the letter "l" is 108, and it occurs three times):
<?php
$str = "Hello World!";
print_r(count_chars($str,1));
?>
|
The output of the code above will be:
Array
(
[32] => 1
[33] => 1
[72] => 1
[87] => 1
[100] => 1
[101] => 1
[108] => 3
[111] => 2
[114] => 1
)
|
Example 2
In this example we will use the count_char() with mode 3 to check the string.
Mode 3 will return a string with all the different characters used:
<?php
$str = "Hello World!";
echo count_chars($str,3);
?>
|
The output of the code above will be:
Complete PHP String Reference
Make your web applications look like a million bucks
|
|
Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.
FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc.
and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise
whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our
12,000 customers and 150,000 users which include a majority of the Fortune 500 companies.
And yeah, your applications could look like a million bucks by spending just $69.
So go ahead, download your
copy of FusionCharts and start "wow-ing" your customers now!
|
 |
W3Schools' Online Certification Program
The perfect solution for professionals who need to balance work, family, and career building.
More than 4000 certificates already issued!
|
The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
|