note 106320 added to function.ini-get

From: Date: Thu, 27 Oct 2011 10:49:26 +0000
Subject: note 106320 added to function.ini-get
Groups: php.notes 
Request: Send a blank email to php-notes+get-184164@lists.php.net to get a copy of this message
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)))))); } ---- Server IP: 69.147.83.197 Probable Submitter: 195.66.81.4 ---- Manual Page -- http://www.php.net/manual/en/function.ini-get.php Edit -- https://master.php.net/note/edit/106320 Del: integrated -- https://master.php.net/note/delete/106320/integrated Del: useless -- https://master.php.net/note/delete/106320/useless Del: bad code -- https://master.php.net/note/delete/106320/bad+code Del: spam -- https://master.php.net/note/delete/106320/spam Del: non-english -- https://master.php.net/note/delete/106320/non-english Del: in docs -- https://master.php.net/note/delete/106320/in+docs Del: other reasons-- https://master.php.net/note/delete/106320 Reject -- https://master.php.net/note/reject/106320 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184164) next »