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!
Related Articles
- Why is Validation Important?Validation in your webpages is very important as proven in this tutorial. In this tutorial youll learn about Validation and how you should be making the effort to get validated!
- Content is Key to Web Site SuccessNo matter how flashy or great your Web site looks, if you dont have good content you are in a boat without a paddle. I can not count the times that I have said that content is key to a Web sites success. Too many times to count...
- Web Design Don'tsIn this webmaster tutorial I will show you some of the basic things that a LOT of webmasters do, that are just plain wrong!
- Tools of the SEO and SEM TradeThe Internet provides a great resource for a wide variety of web marketing and search engine optimization tools for website designers, webmasters and website marketers. SEO and SEM tools provide important and relevant information regarding your websites performance, keywords and keyword placement,....
- Are You SURE Your Link Partners Still Link To You?Its a fact. While most link partners are scrupulously honest a few are little more than link scam artists. Theyll take a link from you to them. Put up your link back. But then when youre not looking take yours down. They win. You lose. Now Im not saying this happens a lot. But it does...
- Check Your Links With These Free ToolsWhile these link checking tools are far from new, you may not have heard of them, or may have some tools to add to the mix or suggestions of how to use these particular tools more effectively.
Whats your favorite link checker? - Link Popularity: Improve your Search Engine RankingsLink Popularity is simply the total number of pages that link to your website. Most search engines, including Google, consider that when one page links to another page, it is effectively casting a vote of confidence for the other page...
- 3 Tips for Choosing the Right Domain NameSelecting the right domain name is one of the most important business decisions you can make. When you have a business online, you are competing in a global economy with millions of other websites.
- Top 7 Web Domain Name Registration MistakesPicking the right domain name can often be hard to do. Take a look at this article to find out the 7 big mistakes people often make when choosing a domain name.
- How to Pick the Perfect Domain NameWhat makes the perfect domain name?
Well, it has to be:
Relatively short Simple to remember Easy to spell I was speaking to a customer recently who had a business called Otway Valley Trading Company.
