I love working magic on strings.
I think you could, (and should) also use a trim feature http://php.net/manual/en/function.trim.php to remove spaces at the start and end.
As far as spaces in the middle, if you really want to get creative you could remove all spaces before doing your comparison.
Here are some things to consider solving for.
Same search different order. "mix together" vs "together mix" .. it's the same search
deal with "S", "ED" or "ING" on the end of strings and remove them before comparing. "Water bottle" and "water bottles" are the same search.
Remove all dashes and special characters "red-car" vs "red car"
That's just some ideas for now.
This is GREAT,... keep it up! 🙂