note 26681 deleted from function.phpversion by maxim
| From: | maxim@php.net | Date: | Fri, 08 Nov 2002 21:01:07 +0000 |
| Subject: | note 26681 deleted from function.phpversion by maxim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-39197@lists.php.net to get a copy of this message | ||
Interfear's Jun 9 example could benefit from intval, but the following examples have another
problem.
Consider testing version 3.0.19 (hypothetical) against 4.1.0. Given the str_replace(), we end up
with:
if ( 3019 >= 410 )
Which returns true even though the version is much older.
So, something like this should work better:
function check_phpver($version) {
// split versions into arrays.
$test = explode( '.', $version );
$curr = explode( '.', phpversion() );
// do intval conversion.
foreach( $test as $k => $v ) {
$test[$k] = intval($v);
}
foreach( $curr as $k => $v ) {
$curr[$k] = intval($v);
}
// do comparison.
if ( $test[0] < $curr[0] ) { return true; }
if ( $test[0] == $curr[0] && $test[1] < $curr[1] ) { return true; }
if ( $test[0] == $curr[0] && $test[1] == $curr[1] && $test[2] <= $curr[2] ) {
return true;
}
return false;
}