public static function instance($api_key) { if (self::$instance == NULL) { if (!isset($api_key) || $api_key == "YOUR_API_KEY" || trim($api_key) == '') { throw new Exception("You need to specify a valid api_key!"); } self::$instance = new Wordnik($api_key); } return self::$instance; }
<?php require "Wordnik.php"; $api_key = "YOUR_API_KEY"; // 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