If you have a user input that may contains some error you can try to check the spelling using Google Spelling Suggestion service (there is an api and you have to register to have an api key to use their web services).
But you can obtain the same result searching the Google search engine and parsing the html code to find the link after the phrase: “Did you mean“. You can think at this code as a mini web bot spell checker.
This code works in any language, it finds the anchor tag that has the classname set to “spell”:
echo doGoogleSpelling("wokipedia"); //returns "wikipedia" function doGoogleSpelling($q) { // grab google page with search $web_page = file_get_contents( "http://www.google.it/search?q=" . urlencode($q) ); // put anchors tag in an array preg_match_all('#<a([^>]*)?>(.*)</a>#Us', $web_page, $a_array); for($j=0;$j<count($a_array[0]);$j++) { // find link with spell suggestion and return it if(stristr($a_array[0][$j],"class=spell")) return strip_tags($a_array[0][$j]); } return ""; }
Thanks, this is really good. It even works with different languages, though it’s a bit slow one can use ajax to compensate that. Thanks again.
I really preferred Do spelling using google spell checker – Barattalo. But it is the quality, not quantity, of the links that is certainly crucial. The other websites really should be relevant to your industry, and preferably highly regarded themselves.