What is the most efficient way to count all the occurrences of a specific character in a PHP string?

use this:

echo substr_count("abca", "a"); // will echo 2

Leave a Comment