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)
Need help adding a timestamp to my filename/variable
Hello,
I'm kind of stupid when it comes to php and I need a tiny bit of help. I've got a f
Reg Ex
Im trying to search for the string: srv_9 (Dead ???)
I thought to use preg_match, however I d
help need on ob_start()
Hi
I am a newbie in php, I have a code
Line number On/Off | Expand/Contract <?phpo
login from external site
Hi my new experience begins, Now what i am trying to do is i make three pages, login.php logout.php
PHP IMAGE UPLOAD SCRIPT
Hi for the last week i have been looking for scripts that will upload a photo to a certain folder wh
FILTER_CALLBACK -- Files?
Hi All,
I'm using the php filter functions to validate my form data. For custom filters, I'm
MFC GUI Programming
I am working on a project right now that requires me to create a MFC Windows GUI. Basically it need
problems with search form numerical "between" sending by php
I am trying to display the results of a search, on a sql database, on a web page. I set up html &quo
LOOPing Problem
Hello All!
The following code loops through the data and displays the data accordingly. My p