php 匹配函数
我正在寻找执行此选项的函数:
preg_match("/^{$STRING}/i", ...)
但是,没有正则表达式,并且第一个中必须有 ^
,这意味着该表达式将为 false:
$search = "hi", $search_in "ahi";
它必须位于细绳。
I am looking for function which does this option:
preg_match("/^{$STRING}/i", ...)
but, without regular expression, and there must be the ^
in the first, which means that this expression will be false:
$search = "hi", $search_in "ahi";
it must be at the start of the string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不确定我是否很好地理解了您的请求...但是...尝试一下:
请注意,您需要使用 3 个
=
符号,因为当字符串中没有匹配项时该函数将返回 false。Not sure I understood your request well... But... Try this:
Please note that you need to use 3
=
signs, because the function will return false when there is no match in the string.用于此目的的精确函数是
strncasecmp
。我不知道为什么最近每个人都如此热衷于stripos
解决方法。尽管它需要字符串长度进行比较,并且结果必须对正匹配取反。
优点是它实际上只比较前 6 个字符。它不会搜索整个主题,并且需要事后进行额外的比较。 (如果用作微优化,那就太愚蠢了。但它正是该任务的函数。)
The exact function for that purpose is
strncasecmp
. I have no idea why everyone is so bent onstripos
workarounds recently.Albeit it needs the string length for comparison, and the result must be negated for positive matches
The advantage is that it really only compares the first 6 characters. It does not search the whole subject and require an extra comparison afterwards. (Stupid if used as microoptimization. But it's the exact function for that task.)