In this tutorial you will learn the basics of the Google Web API, and create your own spell checker!
Note: Your php version must have SOAP compiled and enabled!
For this tutorial, you will need the google web api and an api key, both available from http://www.google.com/apis/ Also, I assume you have some knowledge of how classes and arrays work.
|
<?php
$s = new SoapClient('google-api.wsdl'); $phrase = 'an incoretc setnacne'; $arguments = array('key' => 'your api key', 'phrase' => $phrase); $corrected = $s->__call('doSpellingSuggestion', $arguments); echo "$phrase<br />n$corrected"; ?> |
Here is our script, now to break it down!
What this does is creates a new SoapClient class
|
$s = new SoapClient('google-api.wsdl'); Now we define a few variables
$phrase = 'an incoretc setnacne'; $arguments = array('key' => 'your api key', 'phrase' => $phrase); The first one is just a mispelled sentance, that will be corrected to "an incorrect sentance" |
Now the second one is an array, with defined keys.
One of the keys is "key", place your google web api key here.
The second is "phrase", which is the above variable, change it if you want.
Now we create a variable, and give it the corrected value.
This is one of the function in our SoapClient class, it executes "doSpellingSuggestion" inside the api.
|
$corrected = $s->__call('doSpellingSuggestion', $arguments); Finally, we output our old phrase, and the corrected phrase
echo "$phrase<br />n$corrected"; This script would output |
an incoretc setnacne
an incorrect sentence
Now you're done, it's that simple to make a spell checker!












