如何使此preg_match大小写不敏感?
考虑:
preg_match("#(.{100}$keywords.{100})#", strip_tags($description), $matches);
我试图在每一侧只显示100个字符,中间是搜索字符串。
此代码实际上有效,但它区分大小写。如何使其不区分大小写?
考虑:
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;