simplest, shortest way to count capital letters in a string with php?

count, letters, php

Solution

function count_capitals($s) {
  return mb_strlen(preg_replace('![^A-Z]+!', '', $s));
}

Problem

I am looking for the shortest, simplest and most elegant way to count the number of capital letters in a given string.

Original source