Do spelling using google spell checker

If you have a user input that may contains some error you can try to check the spelling using Google…

November 10, 2009

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( "" . 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 "";


I'm a software engineer, an everyday web developer and a maker. I usually build sites with PHP, within or without WordPress. I build Internet of Things with Arduino and ESP8266. I'm the founder of and and I'm actually the Chief Technical Officer of Better Days web agency.

Comments on “Do spelling using google spell checker”

2 thoughts

  1. Jeremiah says:

    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.

  2. 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.

Comments are closed


PHP bot to grab meteo information from Google

Google has many usefull functions that give you data fast, such as cinema infos, or for meteo forecasts. I think…

December 24, 2009

How many times a web link has been shared on Twitter

Twitter share button and Facebook share button are the most used buttons to share links on Internet. You can read…

October 19, 2012

get MySpace events with a PHP function

Here is a function to read the concerts for a myspace band page. This code retrieves the “shows page” for…

February 21, 2011

Parsing Flickr Feed with PHP tutorial

I’ve spent about 30 minutes to find a javascript embed to print out a custom thumbs list of flickr photos,…

May 30, 2010

PHP to get twitter infos and avatar

I’ve just updated the Mini Bot Php Class with an improved version of the twitterInfo function, here is the code…

March 1, 2010

New version of Mini Bots PHP Class (v.1.4)

I’ve added three more bots to the Mini Bots Php Class, now the version number is 1.4 and it has…

January 20, 2010