A google style Did you mean PHP script

did you mean php

Did you mean

This tutorial about building a php script which can work as spell checker just like “Did you mean” in google search results .When you search for a misspelled word in google it shows you results with correct spelling or results with misspelled word saying did you mean  “correct spelling”.For example if you search for “hostng” in google it will show “Did you mean hosting”.In this tutorial we will use levenshtein() of PHP to identify  the correct word.

So let’s start the coding of a Google style Did you mean PHP script.

1).Assign all correct words in an array-You need an array which contains all possible word which you want to check for spelling.

 2).Calculate distance –Calculate the distance between input and all words using levenshtein().

3).Display the correct word-Show the word as output for which $lev value is minimum.

Here is the complete code . See Demo


  • roskis

    You probably want to add strtolower to $input, since levenshtein is case-sensitive.

  • The best script ever written, very perfect…were you a Google Enginner?

  • Bùi Lê Chí Bảo

    Hi but I want to hide the list of did you mean keywords from visitor. How?