使用爆炸结合单词

I wonder how to solve this problem.

The user gives me a sentence, for example: "I love to code". I have a keyword named "love to code" in my database, and want to see if a keyword is in the given sentence.

So i'll get all keywords out of the database, loop over them and see if there is a preg_match. Now comes the problem, a lot of people make typo's. I thought about comparing the keywords with the words in the sentence via the levenstein method.

Thee problem is the explode function. Since my keyword is made up of multiple words, the explode function will break the whole sentence into single words. Thereby my keyword isn't recognized. Is there a way to split the above sentece in multiple combinations and not only single words?

I was thinking about removing all the whitespaces from $input. (will become "ilovetocodr") do the same for the db sentaces and use levenshtein.

This code will work, but only for keywords that are a single word. The explode function will seperate the sentence into single words.

$input = 'I love to codr';

$keywords = \Layla\Keyword::all();
$words = explode(' ', $input);

foreach ($words as $word) {
    foreach ($keywords as $keyword) {
        $similarity = levenshtein($word, $keyword);
        if ($similarity <= 1) 
            print "$keyword is similar to $word";
    }
}

Then I tried to remove spaces and compare the keyword with the sentence, but then the difference is to big (was expecting this).

$sentence = 'ilovetocodrandstuff';
$keyword = 'ilovetocode';

$similarity = levenshtein($sentence, $keyword);

echo $similarity;

Will output 9.