【发布时间】:2012-09-06 19:44:57
【问题描述】:
考虑:
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 修饰符,则模式中的字母匹配大小写字母。
【讨论】:
另一种选择:
<?php
$n = preg_match('/(?i)we/', 'Wednesday');
echo $n;
【讨论】: