Posted By


mattlowden on 01/20/11

Tagged


Statistics


Viewed 88 times
Favorited by 0 user(s)

count_occurences


/ Published in: PHP
Save to your folder(s)

Count occurences of a list of characters in a given string


Copy this code and paste it in your HTML
  1. function count_occurences($char_string, $haystack){
  2. $characters = str_split($char_string);
  3. $character_count = 0;
  4. foreach($characters as $character){
  5. $character_count = $character_count + substr_count($haystack, $character);
  6. }
  7. return $character_count;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.