CoderZone.org

Category: >> PHP Code >> Count capital letters in a string Bookmark and Share

<< lastnext >>

Snippet Name: Count capital letters in a string

Description: Two easy ways to find how many capital letters there are in a string.

Also see:
» SEO string generator
» Match all #RRGGBB or #RGB values i...
» Remove empty lines from a string o...
» Automatically find location of jav...
» Find first non-numeric character i...
» Read a web page directly in to a s...
» Multi-line variables and strings i...
» Convert a String to Title Case in ...
» Count all words in a string
» Count specific characters in a str...
» Regexp: Find and highlight repeate...
» Create an array from comma separat...
» Create an array from a range of le...
» Convert Unix time string to a date...
» Find Symlink Targets
» Capitalize The First Word In A Sen...
» Super Fast Prime Number Finder
» Find Percentage Function
» Time left In Weeks, Days, Hours, A...
» Find All Elements By Class
» Count Uppercase Letters In A String
» Pre-populated List of Countries
» Neatly trim a string to a set numb...
» Search array elements for a substr...
» Add a period at the end of a strin...
» Search All Words Of A String In my...
» Remove Extra Spaces From A String
» Get Query String with Javascript
» Create string by formatting an amo...

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

 
function count_capitals($str) {
  return strlen(preg_replace('![^A-Z]+!', '', $str));
}
 
 
// or...
 
str_replace(range('A', 'Z'), '', $str, $num_caps);
 
print "Number of capital letters: $num_caps";
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 9