Consider:
preg_match("#(.{100}$keywords.{100})#", strip_tags($description), $matches);
I'm trying to show only 100 characters in each side with the search string in the middle.
This code actually works, but it is a case sensitive. How do I make it case insensitive?
By default, the comparison of an input string with any literal characters in a regular expression pattern is case-sensitive, white space in a regular expression pattern is interpreted as literal white-space characters, and capturing groups in a regular expression are named implicitly as well as explicitly.
The preg_match() function returns whether a match was found in a string.
The preg_match() function will tell you whether a string contains matches of a pattern.
Just add the i
modifier after your delimiter #
:
preg_match("#(.{100}$keywords.{100})#i", strip_tags($description), $matches);
If the i
modifier is set, letters in the pattern match both upper and lower case letters.
Another option:
<?php $n = preg_match('/(?i)we/', 'Wednesday'); echo $n;
https://php.net/regexp.reference.internal-options
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