note 88440 added to function.version-compare

From: Date: Sat, 24 Jan 2009 00:39:39 +0000
Subject: note 88440 added to function.version-compare
Groups: php.notes 
Request: Send a blank email to php-notes+get-149722@lists.php.net to get a copy of this message
Here's another one :) Some ideas from around the documentation are borrowed and put together into this function <? function versionCompare($version1, $operator, $version2) { //get rid of stuff after the 'clean' version: remove '-abc' from '5.2.6-abc' if ( $v1 = substr($version1, 0, strpos($version1, '-') ) ) ; else $v1 = $version1; if ( $v2 = substr($version2, 0, strpos($version2, '-') ) ) ; else $v2 = $version2; // make sure versions like 5.2.0/5.2 and 5.2./5.2.0 and some other variations are treated as equal if ( strlen($v1) != strlen($v2) ) { $m1 = explode('.', $v1); $m2 = explode('.', $v2); if ( ( empty($m1[2]) || $m1[2]=='0' ) && ( empty($m2[2]) || $m2[2]=='0' ) ) { unset($m1[2]); unset($m2[2]); if ( ( empty($m1[1]) || $m1[1]=='0' ) && ( empty($m2[1]) || $m2[1]=='0' ) ) { unset($m1[1]); unset($m2[1]); if ( ( empty($m1[0]) || $m1[0]=='0' ) && ( empty($m2[0]) || $m2[0]=='0' ) ) { unset($m1[0]); unset($m2[0]); } } } $v1 = implode('.', $m1); $v2 = implode('.', $m2); //echo '<br />v1='.$v1.' v2='.$v2.'<br />'; } return version_compare( $v1, $v2, $operator ); } ?> ---- Server IP: 217.75.128.29 Probable Submitter: 87.120.212.51 ---- Manual Page -- http://www.php.net/manual/en/function.version-compare.php Edit -- https://master.php.net/note/edit/88440 Del: integrated -- https://master.php.net/note/delete/88440/integrated Del: useless -- https://master.php.net/note/delete/88440/useless Del: bad code -- https://master.php.net/note/delete/88440/bad+code Del: spam -- https://master.php.net/note/delete/88440/spam Del: non-english -- https://master.php.net/note/delete/88440/non-english Del: in docs -- https://master.php.net/note/delete/88440/in+docs Del: other reasons-- https://master.php.net/note/delete/88440 Reject -- https://master.php.net/note/reject/88440 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#149722) next »