Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
考虑:
preg_match("#(.{100}$keywords.{100})#", strip_tags($description), $matches);
我试图在每边只显示 100 个字符,中间是搜索字符串。
此代码确实有效,但区分大小写。如何使它不区分大小写?
只需i在分隔符后添加修饰符#:
i
#
preg_match("#(.{100}$keywords.{100})#i", strip_tags($description), $matches);
如果i设置了修饰符,则模式中的字母匹配大小写字母。
另外一个选项:
<?php $n = preg_match('/(?i)we/', 'Wednesday'); echo $n;
https://php.net/regexp.reference.internal-options