Created
November 25, 2009 07:56
-
-
Save seanmccann/242548 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 | |
// list of words to find in string | |
$words = array('barack obama', 'chicago', 'nba'); | |
// string to search | |
$sentence = "Barack Obama is from Chicago. Barack Obama's favorite food it pizza."; | |
$res = array(); // results array | |
// see how many times each word occurs in the sentence | |
foreach($words as $word){ | |
$res[$word] = substr_count(strtolower($sentence),$word); | |
} | |
// dump the result array to show results | |
echo var_dump($res); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment