Skip to content

Instantly share code, notes, and snippets.

@noahbass
Created July 13, 2013 00:43
Show Gist options
  • Save noahbass/5988874 to your computer and use it in GitHub Desktop.
Save noahbass/5988874 to your computer and use it in GitHub Desktop.
For getting the word of the day from dictionary.com and displaying it nice and pretty.
<?php
// adapted from http://bavotasan.com/2010/display-rss-feed-with-php/
$rss = new DOMDocument();
$rss->load('http://dictionary.reference.com/wordoftheday/wotd.rss'); // calling dictionary.com
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue
);
array_push($feed, $item);
}
$limit = 1;
if ($feed == null) echo "An error occurred when the robot tried to get the quote of the day.";
else
for ($x=0;$x<$limit;$x++) {
// title
$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
list($title) = explode(':', $title, 2); // remove colon
$title = ucfirst($title); // capitalize first character
// link
$link = $feed[$x]['link'];
// description
$description = $feed[$x]['desc'];
$description = strstr($description, ':'); // remove first word (title)
$description= ltrim($description,': '); // trim first character and whitespace
$description = ucfirst($description); // capitalize first letter
echo '<p>Word of the Day: <strong><a href="'.$link.'" target="_blank" title="Dictionary.com Word of the Day">'.$title.'</a></strong><br />';
echo '<p>'.$description.'</p>';
}
@i2
Copy link

i2 commented Aug 15, 2024

The URL for wotd.rss seems to be outdated now (last post is from 2 years ago). Any new feeds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment