Last active
January 23, 2020 22:43
-
-
Save MalikAQayum/9ead00b258a2fdab39adfff55f700d7a to your computer and use it in GitHub Desktop.
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 | |
| /*create variables*/ | |
| $title =""; | |
| $link =""; | |
| $description = ""; | |
| $pubDate =""; | |
| /*Store RSS feed address in new variable*/ | |
| $url = "http://store.steampowered.com/feeds/news.xml"; | |
| /*Retrieve BLOG XML and store it in PHP object*/ | |
| $xml = simplexml_load_file($url); | |
| echo '<pre>'; | |
| print_r($xml); | |
| /*Parse blog subtitle into HTML and echo it on the page*/ | |
| $title .= "<h2 class='blog'>" . $xml->title . "</h2><br />"; | |
| echo $subtitle; | |
| /*Go through all the entries and parse them into HTML*/ | |
| foreach($xml->entry as $entry){ | |
| /*retrieve publication date*/ | |
| $xmlDate = $entry->published; | |
| /*Convert XML timestamp into PHP timestamp*/ | |
| $phpDate = new DateTime(substr($xmlDate,0,19)); | |
| /*Format PHP timestamp to something humans understand*/ | |
| $pubDate .= $phpDate->format('l\, F j\, Y h:i A'); | |
| if ($entry->title == "") | |
| { | |
| $entryTitle .= "Untitled"; | |
| } | |
| echo $entry->title; | |
| /*Pick through each entry and parse each XML tree node into an HTML ready blog post*/ | |
| $html .= "<h3 class='blog'>".$entry->title . "<span class='pubDate'> | " .$pubDate . "</span></h3><p class='blog'>" . $entry->content . "</p>"; | |
| /*Print the HTML to the web page*/ | |
| echo $html; | |
| /*Set the variables back to empty strings so they do not repeat data upon reiteration*/ | |
| $html = ""; | |
| $pubDate = ""; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment