Hello,
I am trying to get a dictionary definition from the Wordnik API. I copied the code below from their example and it's not working. I've played around with it and I can't see what's wrong. I get this error: "Parse error: syntax error, unexpected $end on line 56".
If you could help me to get this working that would be wonderful. Thank you all for your time.
<?php
require("Wordnik.php");
$api_key = "/*MY API KEY WAS HERE IT WAS REMOVED TO SAFEGUARD */";
// create an instance of the Wordnik class, to make api calls
$wordnik = Wordnik::instance($api_key);
// get the Word of the Day
$wotd = $wordnik->getWordOfTheDay();
$wotd = $wotd->wordstring;
// if the user pressed the "I'm Feeling Wordie" button, fetch a random word and set it to $wordstring
if (isset($_GET['commit']) && ($_GET['commit']=="I\'m Feeling Wordie")) {
$word = $wordnik->getRandomWord();
$wordstring = $word->wordstring;
} else if (isset($_GET['word'])) { // the user is searching for a specific word, either via the form or a link
$wordstring = $_GET['word'];
}
?>
<html>
<head>
<title>Hello, Dictionary!</title>
</head>
<body>
<div>
<h1>Hello, Dictionary!</h3>
<h3>The Wordnik Word of the Day for <?php echo(date("l F j, Y")) ?> is... <strong><a href="/hello_dictionary.php?word=<?php echo(urlencode($wotd)) ?>"><?php echo($wotd) ?></a></strong>!
</h3>
<p>
<form method='get' action='/hello_dictionary.php'>
Look up a word:
<input type='text' name='word' />
<input type='submit' name='commit' value='Search' />
<input type='submit' name='commit' value="I'm Feeling Wordie" />
</form>
</p>
<?php if (isset($wordstring)): ?>
<hr />
<!-- Definitions -->
<div>
<?php $definitions = $wordnik->getDefinitions($wordstring); ?>
<h2>Definitions of <em><?php echo($wordstring) ?></em></h2>
<?php if (empty($definitions)): ?>
<em>Sorry, we couldn't find any definitions!</em>
<?php else: ?>
<ul>
<?php
foreach($definitions as $definition) {
if (isset($definition->text)) {
echo("<li>".$definition->text."</li>");
}
}
?>
</ul>
<a href="http://wordnik.com/words/<?php echo(urlencode($wordstring)) ?>">more definitions</a>
<?php endif ?>
</div>