-
-
Save i2/88a17e35342f530a1f615dc566f4baaf 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(' & ', ' & ', $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>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment