note 106320 deleted from function.ini-get by danbrown

From: Date: Thu, 27 Oct 2011 14:02:15 +0000
Subject: note 106320 deleted from function.ini-get by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-184174@lists.php.net to get a copy of this message
Note Submitter: Marc ---- Arguably the 1024*1024*1024 is more readable than the magic numbers (although commenting would sort that out). Just for fun here's a one-liner that does the same thing. Performance should be on par with the previous post (apart from the rearranging by "most used" case) but there's less to compile and/or interpret, which should ultimately result in a performance win despite the extra function calls to strpos and pow. Also, extending the code to handle terabytes, petabytes, exabytes etc. is a matter of appending the string with t,p,e and whatever unit comes next and won't need specifying any further magic numbers. function return_bytes($size_str) { return (int)$size_str*pow(1024,(1+(-1+strpos("?kmg",strtolower(substr($size_str,-1)))))); }

« previous php.notes (#184174) next »