我正在从雅虎天气预报系统为伦敦和纽约提供的饲料中提取天气数据。 我试图通过重新使用含有在天气数据中提取功能的PHP文档来减少代码重复。
下面是我所说的职能——get_ Current_weather_data(
。 这一职能与其他职能相径庭,如get_city(
和get_temperature(
>功能。
<?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;
}
在我的<代码>index.php上 我将RSS的URL作为“$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 ;
?>
我试图在我的<代码>中点燃——目前——数据(代码)功能中使用:
(if (isset($sourceFeed)) { echo $sourceFeed; }).
然而,我收到以下错误:
"Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in C:xampphtdocsTwinz2
yWeather.php on line 10
Weather not found! Check feed URL".
页: 1
(if (isset($sourceFeed)) { echo $sourceFeed; })
而用URL为它所投入的饲料,这将阻止我重新使用该守则。 我试图做的是不可能做的事,还是我的辛迪加不正确吗?
This isset
method works fine where used elsewhere like for example the $tabTitle
and
$pageIntroductionHeading
variables just need for the RSS feed.
提前感谢。