Last active
April 23, 2020 14:33
-
-
Save cdrubin/b9d7a3d16ac67546ff5f0d270774de7c to your computer and use it in GitHub Desktop.
shared
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
| function count_instances_of_word_in_string( $word, $string ) { | |
| $found = 0; | |
| $matches = preg_match( $word, $string ); | |
| return count( $matches ); | |
| } | |
| $paragraph = <<<EOP | |
| This is some text and I expect there will be some | |
| some words that appear more than once. Especially if | |
| I use the pronoun I more than once and even the word | |
| more will appear more than once at this point. | |
| EOP; | |
| echo count_instances_of_word_in_string( 'more', $paragraph ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment