I'm looking for a quick and easy inline function that returns the number of occurences of a character in a string. That is, something like foo(".", "This.is.a.period.delimited.string.") would return 6. preg_match_all() does this, but with the nasty overhead of regular expressions, which is something I'd like to avoid. I could roll my own function, a simple enough exercise (5 lines max), but I'd rather use PHP builtins. sizeof(explode($needle, $haystack)) - 1 works, but it's verbose. I just leafed through the PHP documentation on string functions, but couldn't find anything. Does anyone know of a function that
1) has minimal overhead (so no regex);
2) uses PHP builtins, not a roll-your-own solution; and
3) isn't terribly verbose?
Thanks.