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
7
Other forums
Needing Youtube thumb nail fix.
I have a script on a site that pulls in you-tube videos,
The problem is, that the thumb nails for
Is there a function ... auto send IP
Is there some function that can be sent to a ddns service that returns the ip address of a ddns forw
date("now") prints out wrong date ?
Hi Guys
Anyone know why and how I can fix it ?
Multiple Options for a Single Page
For this example I want to use the Handlers option which is under Fed Admin and all the related codi
Securing a user input - need some confirmation
Hello All,
I am in the process of recoding a large proportion of an e-commerce site, one of t
Add_Months not Easy to Understand
Oracle is number 1, very fast and very easy. But....
OK, I think but have a problem, only 1 pro
Call to undefined function mysql_fetch_accoc()
New to php/mysql coding. What's wrong with this sequence, or am I
just not seeing to obvious?
mysql timestamp manipulation
How could I use a timestamp (e.g 2009-10-30 13:20:35 ), and with php find out if it is:
from
Gaining access to Drop Down Menu Variable
code is below, I am creating a drop down menu. I want to echo the value selected in the drop down me
code help - pagination
Hi all, I have this code, basically a user logs into my site and they get this page.
The pro