erich1 Posted November 7, 2009 Share Posted November 7, 2009 I am drawing text from a web resource. It is numbers about water levels. I then want that string in this case $high_level checked against a variety of numbers which represent high and low water levels. So basically the text is highlighted a different color depending on the water level. Right now as far as I can tell $high_level=73.15 which is greater than 50 and should show us the color yellow and not red. I tried trim in case there was a problem with white space. I dont know what to do... <?php $file = "http://www.environment.alberta.ca/forecasting/data/hydro/tables/BOW-RHIWDIE-WL.txt"; $handle = @fopen($file, "r"); if ($handle) { while (!feof($handle)) { $buffer = fgets($handle); } fclose($handle); $year = date('Y'); $high_level = strrchr($buffer, ' '); $date = substr(strstr($buffer, $year), 0, 16); } ?> <img src="http://www.paddlingabc.com/images/img05.jpg" alt="arrow"> <a target="_blank" href="http://www.environment.alberta.ca/forecasting/data/hydro/tables/BOW-RHIWDIE-WL.txt">Highwood @ Diebel's Ranch:</a><br /> <?php trim ($high_level); echo $high_level; if ($high_level<='15') { echo "<span style=\"background-color: #FF3300\">"; echo $high_level; echo "cms, "; echo $date; echo "</span>"; } elseif ($high_level<='25') { echo "<span style=\"background-color: #FFFF66\">"; echo $high_level; echo "cms, "; echo $date; echo "</span>"; } elseif ($high_level>='50') { echo "<span style=\"background-color: #FFFF66\">"; echo $high_level; echo "cms, "; echo $date; echo "</span>"; } else { echo "<span style=\"background-color: #33FF00\">"; echo $high_level; echo "cms, "; echo $date; echo "</span>"; } if ($highlevel>='50'){ echo 'Higher'; } else{ echo 'error'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180643-trouble-with-numbers-and-using-strings/ Share on other sites More sharing options...
mikesta707 Posted November 7, 2009 Share Posted November 7, 2009 firstly, just use numbers, not numbers inside quotes. so instead of this if ($highlevel>='50'){ do this if ($highlevel>=50){ for all the line that are like that. you may want to try using intval() on the variable also, IE if (intval($highlevel)>=50){ Hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/180643-trouble-with-numbers-and-using-strings/#findComment-953026 Share on other sites More sharing options...
erich1 Posted November 8, 2009 Author Share Posted November 8, 2009 Solved, Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/180643-trouble-with-numbers-and-using-strings/#findComment-953782 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.