note 109410 deleted from function.version-compare by danbrown

From: Date: Mon, 16 Jul 2012 15:04:45 +0000
Subject: note 109410 deleted from function.version-compare by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189172@lists.php.net to get a copy of this message
Note Submitter: nick58 at gmail dot com ---- I see that some people are using rtrim() in their version_compare() alternatives to remove a trailing '.0'. This is not recommended because rtrim() does not just remove '.0' and instead removes each character. Take this for example: <?php // Returns '1.1' echo rtrim('1.10', '.0'); ?> Instead, you should use something like substr() to remove it: <?php // Returns '1.10' $ver = '1.10'; if (substr($ver, -2) == '.0') $actual_version = substr($ver, 0, -2); else $actual_version = $ver; echo $actual_version; ?>

« previous php.notes (#189172) next »