Just like the question says:
Is there a way to invoke case-insensitive substr_count()?
?> The substr_count() function counts the number of times a substring occurs in a string. Note: The substring is case-sensitive.
The strcasecmp() function is a built-in function in PHP and is used to compare two given strings. It is case-insensitive. This function is similar to strncasecmp(), the only difference is that the strncasecmp() provides the provision to specify the number of characters to be used from each string for the comparison.
str_contains() function is case-sensitive. There is no case-insensitive variant of this function.
In PHP, class names as well as function/method names are case-insensitive, but it is considered good practice to them functions as they appear in their declaration.
There is not a native way, you can do:
substr_count(strtoupper($haystack), strtoupper($needle));
You can of course write this as a function:
function substri_count($haystack, $needle)
{
return substr_count(strtoupper($haystack), strtoupper($needle));
}
Be aware of the Turkey test when using case changes to compare strings.
http://www.moserware.com/2008/02/does-your-code-pass-turkey-test.html
From the above:
As discussed by lots and lots of people, the "I" in Turkish behaves differently than in most languages. Per the Unicode standard, our lowercase "i" becomes "İ" (U+0130 "Latin Capital Letter I With Dot Above") when it moves to uppercase. Similarly, our uppercase "I" becomes "ı" (U+0131 "Latin Small Letter Dotless I") when it moves to lowercase.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With