Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: word definition script? [closed]

I am developing a web page on which I am accepting input words from the user, and when the user submits those words, I want to display definition of those words, or wikipedia links of those words for more definition about that word -- something like the following:

Let's say user enetered 5 words:

toast, egg, beans, coffee, tea

Now I want to display them like:

toast  › slices of bread that have been toasted
egg    › animal reproductive body consisting of an ovum or embryotogether with nutritive and protective envelopes
beans  › a small skullcap <link to wikipedia>read more on wikipedia</link>
coffee › a beverage consisting of an infusion of ground coffee beans
tea    › a beverage made by steeping tea leaves in water <link to wikipedia>read more on wikipedia</link>

For those words for which there is no article on wikipedia, no wiki link would be displayed.

Can someone please suggest me some open-source PHP script or package that would do this for me? Alternatively, I'd appreciate any suggestions on how to do this in PHP.

I am more interested in getting data from some other website directly than I am in storing word definitions in my database.

I am using PHP and MySQL.

like image 652
djmzfKnm Avatar asked Oct 21 '09 06:10

djmzfKnm


2 Answers

Explode user's sanitized input into single words by using explode() function and then use Wikipedia API (see api.php) to get definitions or wiki links.
There should be other web services apart from Wikipedia which is providing API access, just Google them. Also this could be a good guide if you want to make it in Javascript.

As a whole, A well-formed API is not language-dependent. Usually it's XML or JSON (see API Data formats, serialized PHP included), for the XML case you can use the native PHP SimpleXML (Guide here) or SimplePie library. just get & parse!

like image 86
sepehr Avatar answered Oct 21 '22 02:10

sepehr


I would suggest you use definition of the selected words fro Google Define. when you type define:beans, you would get a definition list of the word from google. This google search results come from various sources, but the first one is mostly correct.

You need to use Google Search API to search for this word, parse the XML and show the first result to the user.

You can use Google Search API from this tutorial

Quoting from the Google Search API Documentation

The Google AJAX Search API is a Javascript library that allows you to embed Google Search in your web pages and other web applications. For Flash, and other Non-Javascript environments, the API exposes a raw RESTful interface that returns JSON encoded results that are easily processed by most languages and runtimes.


Example: define:cow to Google Search API would return back a lot of definitions. Get the first element of the search result, parse it and show it next to the word.

like image 26
Manish Sinha Avatar answered Oct 21 '22 01:10

Manish Sinha