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…

Novembre 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”:

DEMO

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 "";
}

Author

PHP expert. Wordpress plugin and theme developer. Father, Maker, Arduino and ESP8266 enthusiast.

Comments on “Do spelling using google spell checker”

2 thoughts

  1. Jeremiah ha detto:

    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. Lauren Trisler ha detto:

    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

Recommended

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…

Dicembre 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…

Ottobre 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…

Febbraio 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,…

Maggio 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…

Marzo 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…

Gennaio 20, 2010