MySQL_Narb Posted September 28, 2012 Share Posted September 28, 2012 $version = '1.2'; Also, $latest also returns 1.2 (both should be strings) Any idea why it still say you're outdated? <?php if(!isset($_GET['check_version'])){ echo 'You\'re running version '. $version .'; <a href="?check_version=11">Check if there\'s a new version.</a>'; }else{ $ch = curl_init('http://.../getLatest.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if(($latest = curl_exec($ch)) === false){ echo 'An error occured: '. curl_error($ch); }else{ if($version != $latest){ echo 'You\'re outdated! <a href="http://.../">Download the new version</a>'. $latest; }else{ echo 'You\'re running the latest version.'; } } curl_close($ch); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/ Share on other sites More sharing options...
trq Posted September 28, 2012 Share Posted September 28, 2012 What is your problem? Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381678 Share on other sites More sharing options...
DavidAM Posted September 28, 2012 Share Posted September 28, 2012 Use var_dump() to see what they actually contain (there may be a new-line on one) Type juggling may be converting them to floats, and you can never trust == when comparing floats Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381679 Share on other sites More sharing options...
Barand Posted September 28, 2012 Share Posted September 28, 2012 Looks like the age old problem of equalities with floats. One could really be 1.19999999999999 and the other 1.200000000001. You could try echoing the values to check. The best way to compare floats is to see if the difference is very small. eg if ( abs($x - $y) < 0.00001) { // consider them equal } Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381681 Share on other sites More sharing options...
MySQL_Narb Posted September 28, 2012 Author Share Posted September 28, 2012 var_dump returns: array(2) { [0]=> string(157) "1.2 " [1]=> string(3) "1.2" } And I added type converters to avoid the float problem: if((string)$version != (string)$latest){ Sadly, it still doesn't seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381683 Share on other sites More sharing options...
Pikachu2000 Posted September 29, 2012 Share Posted September 29, 2012 You don't see the difference between those two strings? Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381684 Share on other sites More sharing options...
Barand Posted September 29, 2012 Share Posted September 29, 2012 (edited) One of those strings is 157 chars! edit : (Prior post notification is still crap) Edited September 29, 2012 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381685 Share on other sites More sharing options...
kicken Posted September 29, 2012 Share Posted September 29, 2012 array(2) { [0]=> string(157) "1.2 " [1]=> string(3) "1.2" } See the numbers in parenthesis right after the word string? That is the length of the string. Your first string is 157 characters long, while your second is only 3 characters long. Obviously they do not match each other. Your first string likely contains a lot of spaces padding it's value. You can use trim to remove these spaces. Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381687 Share on other sites More sharing options...
DavidAM Posted September 29, 2012 Share Posted September 29, 2012 var_dump returns: array(2) { [0]=> string(157) "1.2 " [1]=> string(3) "1.2" } There is a visible blank space between the first value and the closing double-quote. There is something else in that string. It also says it is 157 bytes long, so there is definitely something else there. If you dumped it in the browser, use the "view source" feature of your browser to see if there are non-rendering HTML values in there. You are going to have to figure out what is after the "2" and the strip it out. Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381688 Share on other sites More sharing options...
MySQL_Narb Posted September 29, 2012 Author Share Posted September 29, 2012 http://puu.sh/19yPK Well. Apparently my host included a tracker on the blank page. I also used trim before to remove any trailing spaces, I guess that explains a lot. Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381698 Share on other sites More sharing options...
ManiacDan Posted September 29, 2012 Share Posted September 29, 2012 Always always always view the source when you var-dump. Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381700 Share on other sites More sharing options...
DavidAM Posted September 29, 2012 Share Posted September 29, 2012 Always always always view the source when you var-dump. That is the one thing I don't like about var_dump, there is no way to capture the output and send it through htmlspecialchars(). Unless I need the type and length, I generally use: function debug($value) { printf('<PRE>%s</PRE>', htmpspecialchars(print_r($value, true))); } // Then debug($something); Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381701 Share on other sites More sharing options...
ManiacDan Posted September 29, 2012 Share Posted September 29, 2012 I normally use print_r($var,true) for dumping. var_dump really only gives me useful information on booleans. Quote Link to comment https://forums.phpfreaks.com/topic/268896-12-12-false/#findComment-1381705 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.