Hello!
I am using the Urban Dictionary API code below from their site to get definitions of bad words to display on my site.
The problem is displaying it!
The code I currently have is:
require_once '/var/www/httpdocs/nusoap.php';
define('KEY', 'mykey');
$soap = new soapclient('http://api.urbandictionary.com/soap');
$result = $soap->call('lookup', array('key' => KEY, 'term' => 'dro'));
if ($error = $soap->getError()) {
print $error;
} else {
print_r($result);
}
This works "okay", and displays (in show source) things like:
Array
(
[0] => Array
(
[word] => dro
[definition] => HyDROponically grown marijuana, i.e., "homegrown". Pot grown indoors in hydroponic chambers, which regulate light, humidity, and temperature. Usually a higher, more pure quality of weed than that found elsewhere. Whether there are additives such as cocaine in it is a secondary matter - ask honest questions of your dealer. When in doubt - don't buy.
[example] => From Chingy's hit song "Holidae In" -
Get a 12-pack of Coronas, and a ounce o' 'dro, ya know
[author] => papi
[url] => http://www.urbandictionary.com/define.php?term=dro&defid=407665
[defid] => 407665
)
[1] => Array
(
[word] => dro
[definition] => Highly expensive hydroponically grown marijuana. Very Potent
[example] => WE GOT DRO!
Lets smoke that dro!
[author] => DATOMUSABGAY
[url] => http://www.urbandictionary.com/define.php?term=dro&defid=16203
[defid] => 16203
)
and more...
Basically, what I want to do though is only show the top one [1] in the form of:
Word: thewordhere
Definition: the definition here
Description: description here
Lastly, I have found another issue I don't know how to handle. If a word is provided that doesn't exist in the UrbanDcitionary database, it only replies with:
Array
(
)
rather than an error. Is it possible if that happens to output a "Word is not defined"?
I was thinking as I will be included the above modified code into an existing script, if the urbandictionary server doesn't respond, is there a way to make it simply output a message saying that to prevent the script from timing out or dying?
Any help is much appreciated!