bingo12345
bingo12345

Reputation: 13

PHP flexible(?) search on CSV file

struggling here with doing a search on an array, for example:

string1; string2; string3; string4; string5; string6;

If I use preg_match, I can search the array and it will return a result if the search pattern is exactly the same as an item in the array e.g. if the search term is “string1”. My question is, is there a way to return a positive result if the search string doesn’t have an exact match, e.g. if the search term is “my string” it would return all 6 as suggested results. Thanks!

Upvotes: 1

Views: 153

Answers (1)

Elon Than
Elon Than

Reputation: 9765

You can explode this by ;, loop and use similar_text() function to check how similar is keyword with each string and decide if you want it or not.

$percent = 0;
similar_text($keyword, $string, $percent);
if ($percent > 85) {
   // match
}

Upvotes: 0

Related Questions