我使用下面的代码来识别数组中的作者
foreach($authors as $key => $list){
foreach($coauthors as $key => $co){
$searchword = $list['author'];
$matches = array_filter($co, function($var) use ($searchword) { return preg_match("/\b$searchword\b/i", $var); });
if($matches){ // do something cool }
此代码将匹配" bob,s"与" bob,s"来自作者列表但不会匹配" bob,sm"。然而," bob"将与" bob,s"匹配。
我需要这样做,以便#34;作者,我"匹配从这些字符开始的所有内容,而不是寻找目前似乎正在做的整个单词,即它匹配"作者,ii" "作者,iai"等等
修改
我已将我正在打印的输出的屏幕截图附加到屏幕上,希望它能解释我要做的事情。 $ authors是我通过尝试匹配共同作者列表来循环的作者列表。在屏幕截图中,您可以看到作者adam在两个共同作者列表中匹配adam和adam,k。这也适用于亚当斯和亚当斯,但是没有显示为艾哈迈德,米和艾哈迈德,mp(忽略上一作者)的匹配
编辑
请求输出。警告这是巨大的,并且有很多缺少的数据,因为我使用一个小数据集来修复这个错误
searchword=adam, var=, rtn=NO MATCH searchword=adam, var=adam, rtn=MATCH searchword=adam, var=adams, rtn=NO MATCH searchword=adam, var=ahmed, m, rtn=NO MATCH searchword=adam, var=mazzoferro, v, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=1, rtn=NO MATCH searchword=adam, var=0, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=adam, k, rtn=MATCH searchword=adam, var=adams, ky, rtn=NO MATCH searchword=adam, var=ahmed, mp, rtn=NO MATCH searchword=adam, var=mazzoferro, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=2, rtn=NO MATCH searchword=adam, var=0, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=adam, rtn=NO MATCH searchword=adams, var=adams, rtn=MATCH searchword=adams, var=ahmed, m, rtn=NO MATCH searchword=adams, var=mazzoferro, v, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=1, rtn=NO MATCH searchword=adams, var=0, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=adam, k, rtn=NO MATCH searchword=adams, var=adams, ky, rtn=MATCH searchword=adams, var=ahmed, mp, rtn=NO MATCH searchword=adams, var=mazzoferro, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=2, rtn=NO MATCH searchword=adams, var=0, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=adam, rtn=NO MATCH searchword=ahmed, m, var=adams, rtn=NO MATCH searchword=ahmed, m, var=ahmed, m, rtn=MATCH searchword=ahmed, m, var=mazzoferro, v, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=1, rtn=NO MATCH searchword=ahmed, m, var=0, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=adam, k, rtn=NO MATCH searchword=ahmed, m, var=adams, ky, rtn=NO MATCH searchword=ahmed, m, var=ahmed, mp, rtn=NO MATCH searchword=ahmed, m, var=mazzoferro, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=2, rtn=NO MATCH searchword=ahmed, m, var=0, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=adam, rtn=NO MATCH searchword=mazzoferro, v, var=adams, rtn=NO MATCH searchword=mazzoferro, v, var=ahmed, m, rtn=NO MATCH searchword=mazzoferro, v, var=mazzoferro, v, rtn=MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=1, rtn=NO MATCH searchword=mazzoferro, v, var=0, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=adam, k, rtn=NO MATCH searchword=mazzoferro, v, var=adams, ky, rtn=NO MATCH searchword=mazzoferro, v, var=ahmed, mp, rtn=NO MATCH searchword=mazzoferro, v, var=mazzoferro, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=2, rtn=NO MATCH searchword=mazzoferro, v, var=0, rtn=NO MATCH
删除尾随/ b 后输出
searchword=adam, var=, rtn=NO MATCH searchword=adam, var=adam, rtn=MATCH searchword=adam, var=adams, rtn=MATCH searchword=adam, var=ahmed, m, rtn=NO MATCH searchword=adam, var=mazzoferro, v, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=1, rtn=NO MATCH searchword=adam, var=0, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=adam, k, rtn=MATCH searchword=adam, var=adams, ky, rtn=MATCH searchword=adam, var=ahmed, mp, rtn=NO MATCH searchword=adam, var=mazzoferro, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=, rtn=NO MATCH searchword=adam, var=2, rtn=NO MATCH searchword=adam, var=0, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=adam, rtn=NO MATCH searchword=adams, var=adams, rtn=MATCH searchword=adams, var=ahmed, m, rtn=NO MATCH searchword=adams, var=mazzoferro, v, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=1, rtn=NO MATCH searchword=adams, var=0, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=adam, k, rtn=NO MATCH searchword=adams, var=adams, ky, rtn=MATCH searchword=adams, var=ahmed, mp, rtn=NO MATCH searchword=adams, var=mazzoferro, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=, rtn=NO MATCH searchword=adams, var=2, rtn=NO MATCH searchword=adams, var=0, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=adam, rtn=NO MATCH searchword=ahmed, m, var=adams, rtn=NO MATCH searchword=ahmed, m, var=ahmed, m, rtn=MATCH searchword=ahmed, m, var=mazzoferro, v, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=1, rtn=NO MATCH searchword=ahmed, m, var=0, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=adam, k, rtn=NO MATCH searchword=ahmed, m, var=adams, ky, rtn=NO MATCH searchword=ahmed, m, var=ahmed, mp, rtn=MATCH searchword=ahmed, m, var=mazzoferro, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=, rtn=NO MATCH searchword=ahmed, m, var=2, rtn=NO MATCH searchword=ahmed, m, var=0, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=adam, rtn=NO MATCH searchword=mazzoferro, v, var=adams, rtn=NO MATCH searchword=mazzoferro, v, var=ahmed, m, rtn=NO MATCH searchword=mazzoferro, v, var=mazzoferro, v, rtn=MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=1, rtn=NO MATCH searchword=mazzoferro, v, var=0, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=adam, k, rtn=NO MATCH searchword=mazzoferro, v, var=adams, ky, rtn=NO MATCH searchword=mazzoferro, v, var=ahmed, mp, rtn=NO MATCH searchword=mazzoferro, v, var=mazzoferro, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=, rtn=NO MATCH searchword=mazzoferro, v, var=2, rtn=NO MATCH searchword=mazzoferro, v, var=0, rtn=NO MATCH
答案 0 :(得分:1)
这是你的代码:
preg_match("/\b$searchword\b/i", ...
\b
之前和之后$searchword
告诉preg_match,前后单词必须有中断。删除它们,无论文字在哪里打破,它都会匹配。
preg_match("/$searchword/i", ...
编辑 - 进行这些更改,让我们知道输出是什么
foreach($authors as $key => $list){
foreach($coauthors as $key => $co){
$searchword = $list['author'];
$matches = array_filter($co,
function($var) use ($searchword) {
$rtn = preg_match("/\b$searchword/i", $var);
echo "searchword=$searchword, var=$var, rtn=".($rtn?'MATCH':'NO MATCH')."<br />\n";
});
if($matches){ // do something cool }
答案 1 :(得分:1)
这可能就是你要找的东西:
foreach($authors as $list) {
$searchword = $list['author'];
foreach($coauthors as $co) {
$matches = array_filter($co, function($var) use ($searchword) {
return strncasecmp($searchword, $var, strlen($searchword)) == 0;
});
if ( ! empty($matches)) {
// do something cool
}
}
}
来自PHP manual:strncasecmp - 前n个字符的二进制安全不区分大小写的字符串比较
这样做:对于$list['author']
- 值和$co
- 数组的每个组合,$matches
将填充$co
中的所有(字符串)元素以$list['author']
的值开头(不区分大小写的比较)。请注意,$matches
将在每个循环中被覆盖。
更新:我刚做了以下测试:
$authors = array(array('author' => 'ahmed, m'));
$coauthors = array(array('ahmed, m', 'ahmed, mp'));
$allMatches = array();
foreach($authors as $list) {
$searchword = $list['author'];
foreach($coauthors as $co) {
$matches = array_filter($co, function($var) use ($searchword) {
return strncasecmp($searchword, $var, strlen($searchword)) == 0;
});
if ( ! empty($matches)) {
$allMatches[] = $matches;
}
}
}
var_dump($allMatches);
这给出了这个结果:
array (size=1)
0 =>
array (size=2)
0 => string 'ahmed, m' (length=8)
1 => string 'ahmed, mp' (length=9)
所以ahmed, mp
与ahmed, m
匹配。
答案 2 :(得分:0)
无需使用preg_match()。您可以使用strpos();
编写适当的函数检查出来:
$haystack = array('abcde', 'adsfzvabcde', 'bcde', 'abasdfasd', 'cdefg');
$searchWord = 'ab';
$matches = array_filter($haystack, function($haystack) use ($searchWord){
return $searchWord === "" || strrpos($haystack, $searchWord, -strlen($haystack)) !== FALSE;
});
print_r($matches);
它将找到以$ searchWord
开头的所有字符串输出将是:
Array ( [0] => abcde [3] => abasdfasd )
答案基于此function