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

82

考虑:

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

我想在搜索字符串中间仅显示每侧的前100个字符。

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

2个回答

149

在你的定界符(在这种情况下为#)后添加i修饰符即可:

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

如果您的分隔符为/,请在其后添加一个i

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

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


8

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接