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

时间:2012-09-13 16:46:46

标签: php regex

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

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

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

2 个答案:

答案 0 :(得分:87)

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

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

如果设置了 i 修饰符,则模式中的字母会匹配大写和小写字母。

答案 1 :(得分:1)

另一个选择:

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

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

相关问题