Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:44:52+00:00 2026-05-28T04:44:52+00:00

I am pulling in weather data from a Yahoo weather RSS feed for both

  • 0

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';
$pageIntroductionHeading = 'Welcome to our site';
$pageIntroductionContent = 'Twinz is a website which has been created to bring towns together! 
            Our goal is to bring communities around the world together, by providing 
            information about your home town and its twin town around the world. Our 
            site provides weather, news and background information for London and 
            one of its twin cities New York.'; 
$column1Heading = 'Current Weather for New York'; 
$column2Heading = 'Current Weather for London'; 
$column3Heading = 'Current Weather for Paris'; 

$sourceFeed = "http://weather.yahooapis.com/forecastrss?p=USNY0996&u=f"; 

include_once 'header.php';
include_once 'navigationMenu.php';
include_once 'threeColumnContainer.php';
include_once 'footer.php';

?>

I attempt to call the feed in my get_current_weather_data() function using:

(if (isset($sourceFeed)) { echo $sourceFeed; }).  

However, I receive the following error

"Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in C:\xampp\htdocs\Twinz2\nyWeather.php on line 10
Weather not found! Check feed URL".

If I replace

(if (isset($sourceFeed)) { echo $sourceFeed; }) 

with the URL for the feed it works but this will stop me from reusing the code. Am I trying to do the impossible or is my syntax just incorrect?

This isset method works fine where used elsewhere like for example the $tabTitle and
$pageIntroductionHeading variables just need for the RSS feed.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:44:53+00:00Added an answer on May 28, 2026 at 4:44 am

    The problem is in the following line:

    $feed = file_get_contents(if (isset($sourceFeed)) { echo $sourceFeed; });
    

    it has to be:

    if(isset($sourceFeed)){ $feed = file_get_contents($sourceFeed); }
    

    And when you call the function, you also have to pass $sourceFeed as function parameter, like that:

    get_current_weather_data($sourceFeed);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code is pulling from a data cells that lists multiple file paths and
I'm pulling data from an XML feed and manipulating it using the awesome SimpleXMLElement.
I've been using this code to try and get data from the google weather
Accomplished pulling data from JSON, but having problems trying to pull additional information from
Im pulling some data from an xml on a separate site and trying to
Trying to pull a value from the sunrise element from [yweather:astronomy] in the Yahoo
I'm pulling in data from an external place database that returns JSON of information
I am pulling my data from a database and I am using json. What
I need some help pulling cell data from table when a user clicks the
I am currently pulling an RSS feed in which the the format is essentially

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.