Count Specific Characters in String PHP

substr_count is a php inbuilt function with the help of which you can get specific character of any string. I will explain you example deke with the help of expertsphp blog how you get specific characters from a string value by php code so let’s go

exapmle.php

<?php
//you can use the substr_count function
$str = "this is a experts php test string"; 
echo substr_count($str, "s"); //Output: 5
?>

As you have been told by the above exapmle that you can easily extract specific value from the value of string through php code.

How to run this code?

  • First of all, you create a php file, you can name that file whatever you want.
  • Then after that copy the code and paste it in the file of php created by you.
  • Now run this file on your local server or hosting server, you will get the output.