Я использую код ниже, чтобы определить авторов в массиве
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». Тем не менее, «Боб» будет совпадать с «Боб, с».
Мне нужно, чтобы это работало так, чтобы «автор, я» соответствовал всему, что начинается с этих символов, и не искал целые слова, как это происходит в данный момент, то есть соответствует «автор, ii», «автор, iai» и т. Д. И т. Д.
РЕДАКТИРОВАТЬ
Я приложил к экрану скриншот вывода, который я печатаю, в надежде, что он объясняет, что я пытаюсь сделать. $ авторы — это список авторов, который я перебираю, пытаясь сопоставить со списком соавторов. На скриншоте видно, что автор adam совпадает с adam и adam, k в двух списках соавторов. Это также работает для Адамса и Адамса, к.и., но совпадения для ахмеда, м и ахмеда, м.р. не отображаются (игнорировать последнего автора)
РЕДАКТИРОВАТЬ
запрашиваемый вывод. Предупреждение, это огромно и содержит много пропущенных данных просто потому, что я использую небольшой набор данных для исправления этой ошибки
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
вывод после снятия трейлинга / б
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
Вот ваш код:
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 }
Это может быть то, что вы ищете:
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: strncasecmp — двоичное безопасное сравнение строк без учета регистра первых n символов
Что это делает: для каждой комбинации $list['author']
-значение и $co
-array, $matches
будет заполнен всеми (string-) элементами в $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
,
Нет необходимости использовать 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 )
Ответ основан на этом функция