Skip to content

Instantly share code, notes, and snippets.

@nolim1t
Created June 1, 2009 07:15
Show Gist options
  • Save nolim1t/121282 to your computer and use it in GitHub Desktop.
Save nolim1t/121282 to your computer and use it in GitHub Desktop.
Count the number of occurances in a string
<?php
function countwordsInString($string, $delimiter, $word) {
$occurs = 0;
foreach (explode($delimiter, $string) as $stringword) if ($word == $stringword) $occurs++;
return $occurs;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment