Created
April 2, 2013 20:53
-
-
Save hemache/5296082 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function count_words($needed_word, $string) | |
{ | |
$words = str_word_count($string, 1); | |
$words_count = array_count_values($words); | |
// Use multibyte string to lower | |
return $words_count[mb_strtolower($needed_word)]; | |
} | |
/* | |
* Example: count_words("email", "I've got an Email , 1 email was from my daddy !"); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment