I have the following code:
explode("delimiter", $snippet);
But I want that my delimiter is case-insensitive.
Just use preg_split()
and pass the flag i
for case-insensitivity:
$keywords = preg_split("/your delimiter/i", $text);
Also make sure your delimiter which you pass to preg_split()
doesn't cotain any sepcial regex characters. Otherwise make sure you escape them properly or use preg_quote()
.
You can first replace the delimiter and then use explode as normal. This can be done as a fairly readable one liner like this:
explode($delimiter,str_ireplace($delimiter,$delimiter,$snippet));
explode('delimiter',strtolower($snippet));
Never use expensive regular expressions when more CPU affordable functions are available.
Never use double-quotes unless you explicitly have a use for mixing variables inside of strings.
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