How to Count Specific Characters from a String in PHP ?

 

In this blog, we will be going to understand how to count specific characters from a string. This will be going to be very to understand and use. This can be used in some specific cases of your projects.


We will be using the PHP function (substr_count())to count specific characters from strings and we can also count words from sentences.


Here is an example,


Code


<?php

  

    $string = "How to Count Specific Characters from a String in PHP ?"; 

    $findString = "Count"; 

        

    $res = substr_count($string, $findString); 

    echo($res); 

?>


Output:


1



I hope this will help in your projects. Let me know if you have any doubt.