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
small inaccuracies
I have this code to convert fractional base 10 into base 2:
while($num > 0)
php + mysql count consecutive data
I have a database of values and I want to work out how to display them if the values match a consecu
how can i expire the submitted page using session.
hi,
i'm new to php world.
i'm using "post" method.
when i submit it,data goes to
wav to mp3 + goDaddy
I need to convert wav files to mp3s. From what I have found so far one way to do it is to have my PH
File upload issues
Hi Guys,
Can anyone see any issues with this code:
Code: [Select]$setImage= 'productimages
big pagination problem in php
<?php
$connect = mysql_connect("localhost", "root", "")
Production of mango in processing industry
Hi,
We have one scenario ,company is in process industry,they are manufacturing MANGO pul
question about stripslashes and real_escape_string
im cleaning up an old app that I wrote fixing some of the vulernabilities from attacks.
I hav
A WBS element with the name XXX already exists in version FREI_VERSION
Hi.
When I am trying to insert WBS element in a project, error occurs:
"A WBS eleme
Changes to hosting company's server has affected web contact form
I started a thread a couple of months ago about the contact forms on my client's website. Basically