80

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
GianFS
  • 2,545
  • 2
  • 22
  • 21

2 Answers2

145

Just add the i modifier after your delimiter (# in your case):

preg_match("#(.{100}$keywords.{100})#i", strip_tags($description), $matches);

If your delimiter is /, add an i after it :

preg_match("/your_regexp_here/i", $s, $matches); // i means case insensitive

If the i modifier is set, letters in the pattern match both upper and lower case letters.

yaya
  • 7,675
  • 1
  • 39
  • 38
donald123
  • 5,638
  • 3
  • 26
  • 23
7

Another option:

<?php
$n = preg_match('/(?i)we/', 'Wednesday');
echo $n;

https://php.net/regexp.reference.internal-options

Zombo
  • 1
  • 62
  • 391
  • 407