CaSe Insensitive substr_count in PHP: Is There any Elegant Solution?

By | August 26, 2012

Recently I’ve been searching for case insensitive version of substr_count in PHP. I haven’t found any elegant solution, so let me post the simple code that does the trick.

$vsegoslov=substr_count(strtolower($spunator), strtolower($keyword));

I know is’t a piece of dirty code, but I don’t know any other option to do this. You can count the numberĀ  of substring occurrences using Regexp-based functions, but if you don’t want to deal with them, that seems to be the fastest option for case insensitive substr_count.