60

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
  • 28,342
  • 21
  • 95
  • 123
GianFS
  • 2,295
  • 2
  • 20
  • 21

2 Answers2

119

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.

Biffen
  • 5,354
  • 5
  • 27
  • 32
donald123
  • 5,156
  • 3
  • 22
  • 22
2

Another option:

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

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

Steven Penny
  • 82,115
  • 47
  • 308
  • 348