Я пытаюсь сделать ввод не шаблоном.
$input= "words trying to compare";
preg_match("/\b{$input}\b/", "these are a lot of words that i'm trying to compare")
// ^this might contain multiple words, but the same as ^^ these
echo "match is found";
как я могу сделать так, что даже если входные слова не находятся в том же порядке, что и предложение, к которому я пытаюсь его сравнить, он может вернуть "соответствие найдено".
Просто используйте preg_match_all
preg_match_all("/\b{$input}\b/", "these are a lot of words that i'm trying to compare",$matchedWords);
Для нескольких слов:
<?php
$input= "words compare";
$pattern = str_replace(" ","|",$input);
preg_match_all("/{$pattern}/", "these are a lot of words that i'm trying to compare words",$matchedWords);
// ^this might contain multiple words, but the same as ^^ these
var_dump($matchedWords);
$input= "words|trying|to|compare";
$count = preg_match_all('#\b('.$input.')\b#', $string, $matches);
if($count)
echo 'found word';
else
echo 'not found';