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
Search in the PHP Files
have to search asterisk(*) in the php code of the php files .
In the html page one text box
private constructor
Hello,
Can we create a constructor as private? If yes, what is the use of it? If no, why can'
WM transfer order: confirm different batch than proposed by system
Hi folks,
following scenario: we have a full WM with mixed batch numbers allowed in stora
WHYISNT THIS MYSQL STATEMNT NOT WORKING? (php)
caps because its absolutely rediculous.
i dontunderstand why its not working. there is a column c
update 2 columns by doing inner 2-column query
Hi,
is something like this possible?
update contract_all set col1,col2 =
(
DataTable Help Required
Hi all I am creating an app that utilises and MS Access back end and queries it quite a bit at vario
Code working in IE but not FireFox
I created a dynamic navigation list for my website based off of a table in my database. The code is
How to login with SAPCPIC userid
I have changed the Password for SAPCPIC in Development Server for 000,001 and 100 client.
But w
Email Processor
I have a few questions so this post will be a larger one! Sorry, but I'm a bit of a PHP newbie so be
Calling All PHPFREAKS Blackberry Users
Are you a member of PHPFreaks and have a blackberry? Well RIM just recently released Blackberry Mes