Skip to main content

Posts

Showing posts with the label rss

Reusing PHP function to reduce code duplication

I am pulling in weather data from a Yahoo weather RSS feed for both London and New York. I'm trying to reduce code duplication by reusing a PHP file which contains functions for pulling in the weather data. Below is the function I am calling - get_current_weather_data() . This function goes off to various other functions such at the get_city() and get_temperature() functions. <?php function get_current_weather_data() { // Get XML data from source include_once 'index.php'; $feed = file_get_contents(if (isset($sourceFeed)) { echo $sourceFeed; }); // Check to ensure the feed exists if (!$feed) { die('Weather not found! Check feed URL'); } $xml = new SimpleXmlElement($feed); $weather = get_city($xml); $weather = get_temperature($xml); $weather = get_conditions($xml); $weather = get_icon($xml); return $weather; } In my index.php I set the URL for the RSS feed as the variable called $sourceFeed . <?php $tabTitle = ' | Home'; $pageIntroduction