
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
Program to find how many times a character appears in a string in PHP
Example
<?php $str = "welcome to tutorials point"; $str = str_replace(" ","",$str); $arr = str_split($str); foreach ($arr as $key =>$val){ if (!isset($output[$val])){ $output[$val] = 1; } else{ $output[$val] += 1; } } foreach($output as $char =>$number){ echo $char." ".'appears '. $number." ".'times'."
"; } ?>
Output
w appears 1 times e appears 2 times l appears 2 times c appears 1 times o appears 4 times m appears 1 times t appears 4 times u appears 1 times r appears 1 times i appears 2 times a appears 1 times s appears 1 times p appears 1 times n appears 1 times
- Related Articles
- Get count of how many times a string appears in a MySQL column?
- Count how many times the substring appears in the larger String in Java
- Counting how many times an item appears in a multidimensional array in JavaScript
- Number of times a string appears in another JavaScript
- Python Program to Determine How Many Times a Given Letter Occurs in a String Recursively
- PHP program to check if a string has a special character
- Python program to find Most Frequent Character in a String
- Python program to find Least Frequent Character in a String
- How to remove a character (‘’) in string array and display result in one string php?
- C++ Program to Find the Frequency of a Character in a String
- Program to count how many times we can find "pizza" with given string characters in Python
- Check if max occurring character of one string appears same no. of times in other in Python
- C Program to find maximum occurrence of character in a string
- C Program to find minimum occurrence of character in a string
- Java Program to Find the Frequency of Character in a String

Advertisements