如何使这个preg_match不区分大小写?

Gia*_*nFS 49 php regex

preg_match("#(.{100}$keywords.{100})#", strip_tags($description), $matches);
Run Code Online (Sandbox Code Playgroud)

我试图在每一侧只显示100个字符,中间有搜索字符串.

这段代码实际上有效,但它区分大小写,我如何使其不区分大小写?

小智 96

只需i在分隔符后添加修饰符#:

preg_match("#(.{100}$keywords.{100})#i", strip_tags($description), $matches);
Run Code Online (Sandbox Code Playgroud)

如果i设置了修改器,则模式中的字母将匹配大写和小写字母.


小智 8

另外一个选择:

<?php
$n = preg_match('/(?i)we/', 'Wednesday');
echo $n;
Run Code Online (Sandbox Code Playgroud)

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