note 109410 added to function.version-compare

From: Date: Sat, 14 Jul 2012 20:00:40 +0000
Subject: note 109410 added to function.version-compare
Groups: php.notes 
Request: Send a blank email to php-notes+get-189140@lists.php.net to get a copy of this message
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; ?> ---- Server IP: 72.55.140.6 Probable Submitter: 68.146.18.227 ---- Manual Page -- http://www.php.net/manual/en/function.version-compare.php Edit -- https://master.php.net/note/edit/109410 Del: integrated -- https://master.php.net/note/delete/109410/integrated Del: useless -- https://master.php.net/note/delete/109410/useless Del: bad code -- https://master.php.net/note/delete/109410/bad+code Del: spam -- https://master.php.net/note/delete/109410/spam Del: non-english -- https://master.php.net/note/delete/109410/non-english Del: in docs -- https://master.php.net/note/delete/109410/in+docs Del: other reasons-- https://master.php.net/note/delete/109410 Reject -- https://master.php.net/note/reject/109410 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189140) next »