php - Calculate percentage of matching words in a string of words
I have a string with a bunch of words with a space delimiter that comes from my database and another similar string with words from user input.
$usrKeywords = 'test1 test4 test2'; //$_POST['keywords'] $dbKeywords = 'test1 test2 test3 test4 test5'; //from the DB
How can I check the percentage of how many user keywords match the database keywords?
So for the above case it would be 60%.
I know I would have to know how many words there are in total, and then check how many matching user keywords are contained in the db keywords string and then do like
3 / 5 * 100 to get the percentage (for the above example).
But code wise I have no idea how to do this.