考虑:
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;