Quick fix: Conditional statement with an array


Posted on 16th Feb 2014 07:03 pm by admin

Hi, I'm getting the temperature value off of the Environment Canada website along with the icon filename, so I can display my own icons and temperature on my site. All this works and I can display the temperature but my conditional statements aren't working to display my icons. I'm new to PHP and I don't see why this is a problem:
Code: <?php
$url = "http://www.weatheroffice.gc.ca/city/pages/on-69_metric_e.html";
$ch = curl_init();//Initialise CURL
curl_setopt($ch, CURLOPT_URL, $url);//Set the url
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);//We want it to return data
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 100);//Of course, we don't want your script to run forever, so set a timeout
$text = curl_exec($ch);//Execute and get the page

$exploded = explode('<p class="temperature">',$text);//Make an array of the part before and after the <title> tag
$result = explode('<sup>',$exploded[1]);//Grab the part after the <title> tag, and split that too

$exploded2 = explode('<img id="currentimg" src="/weathericons/',$text);//Make an array of the part before and after the <title> tag
$result2 = explode('.gif"',$exploded2[1]);//Grab the part after the <title> tag, and split that too

curl_close($ch);//Close cURL

if($result2[0] < "02"){
echo "<img src="images/weather/00.gif" alt="Sunny">";
}
if(($result2[0] > "01") && ($result2[0] < "09")) {
echo "<img src="images/weather/01.gif" alt="Cloudy with chance of showers">";
}
if($result2[0] == "09" || $result2[0] == "19" || $result2[0] == "39") {
echo "<img src="images/weather/03.gif" alt="Storm">";
}
if(($result2[0] > "9" && $result2[0] < "9") || ($result2[0] > "19" && $result2[0] < "25") || ($result2[0] > "26" && $result2[0] < "30") || ($result2[0] > "31" && $result2[0] < "39")) {
echo "<img src="images/weather/02.gif" alt="Cloudy with chance of showers">";
}
if(($result2[0] > "24" && $result2[0] < "27") || ($result2[0] > "29" && $result2[0] < "32") || ($result2[0] > "39") {
echo "";
}
else{
echo "";
}
echo $result[0];//Echo the result
?>

No comments posted yet

Your Answer:

Login to answer
212 Like 7 Dislike
Previous forums Next forums
Other forums

Help with writing "$" with fopen
I just can't get my syntax correct. Could someone help me please? I am trying to write a connect fil

DB2 for z/OS, LUW, iSeries
Hello, In this forum a lot of threads related to other members of the DB2 family than DB2 for z/OS

Really need helps regarding Pagination with Sort
I need someone helps regarding pagination problem...i actually want to make my page limited to let s

Significance of BPM
Hi Experts,
I am a novice in BPM , I just want to know how BPM as permenant department is

Google Wave
So... has anyone used it yet? Is it any good?

http://wave.google.com/help/wave/about.html#vid

COde for a Cc
I'm not receiving $ft as a Cc. Why is that??

$to = "$email";
$headers = "Fr

Impact of movement type 412 E on MAP
Hi

Usage of movement type 412 E is causing huge change in MAP .

Is there any r

simplexml and xpath - Need some help
Hello,

I am trying to parse an xml which comes back from Amazon and I am trying to know how m

Image resize
Hi again fellers

I managed to sort out the issues with the folder,

Final hurdle is th

Undefined Variable: PHP_SELF, pls help
Hi,

Im a newbie on PHP / MySQL programming and Im running a script to search one field on my

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash