php 如何使这个 preg_match 不区分大小写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12411037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make this preg_match case insensitive?
提问by GianFS
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.
我试图在每边只显示 100 个字符,中间是搜索字符串。
This code actually works, but it is a case sensitive. How do I make it case insensitive?
这段代码实际上有效,但它区分大小写。我如何使它不区分大小写?
回答by donald123
Just add the imodifier after your delimiter #:
只需i在分隔符后添加修饰符#:
preg_match("#(.{100}$keywords.{100})#i", strip_tags($description), $matches);
If the imodifier is set, letters in the pattern match both upper and lower case letters.
如果i设置了修饰符,则模式中的字母将同时匹配大写和小写字母。

