[英]How do I make this preg_match case insensitive?
考虑:
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
$n = preg_match('/(?i)we/', 'Wednesday');
echo $n;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.