考虑:
preg_match("#(.{100}$keywords.{100})#", strip_tags($description), $matches);
我试图在每一侧仅显示 100 个字符,中间是搜索字符串。
这段代码确实有效,但区分大小写。如何使其不区分大小写?
最佳答案
只需在分隔符后添加 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
修饰符,则模式中的字母同时匹配大小写字母。
关于php - 如何使这个 preg_match 不区分大小写?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12411037/