Programming Tutorials

Count occurrences of a character in a String in PHP

By: Kani in PHP Tutorials on 2012-04-05  

Here is another simple example for - for loops. Thsi PHP code shows how to search for a particular character in a String and count the number of occurrences of that character in that string.

$text="Welcome to PHP";
$count="0"; //zero
for($i="0"; $i<strlen($text); $i=$i+1){

echo $count

this will count how many times the character "e" occurs in that text (Welcome to PHP).

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)