note 126769 added to function.ini-get

From: Date: Sun, 16 Jan 2022 10:44:22 +0000
Subject: note 126769 added to function.ini-get
Groups: php.notes 
Request: Send a blank email to php-notes+get-217498@lists.php.net to get a copy of this message
Here is a version combining a few of the examples here that does *not* require php8 nor does it generate a warning /** * gets the value in bytes converted from a human readable string like 10G' * * @param mixed $val the human readable/shorthand version of the value * @return int the value converted to bytes */ function return_bytes($val) { $val = trim($val); preg_match('/([0-9]+)[\s]*([a-zA-Z]+)/', $val, $matches); $value = (isset($matches[1])) ? intval($matches[1]) : 0; $metric = (isset($matches[2])) ? strtolower($matches[2]) : 'b'; switch ($metric) { case 'tb': case 't': $value *= 1024; case 'gb': case 'g': $value *= 1024; case 'mb': case 'm': $value *= 1024; case 'kb': case 'k': $value *= 1024; } return $value; } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 70.44.33.193) ---- Manual Page -- https://php.net/manual/en/function.ini-get.php Edit -- https://main.php.net/note/edit/126769 Del: integrated -- https://main.php.net/note/delete/126769/integrated Del: useless -- https://main.php.net/note/delete/126769/useless Del: bad code -- https://main.php.net/note/delete/126769/bad+code Del: spam -- https://main.php.net/note/delete/126769/spam Del: non-english -- https://main.php.net/note/delete/126769/non-english Del: in docs -- https://main.php.net/note/delete/126769/in+docs Del: other reasons-- https://main.php.net/note/delete/126769 Reject -- https://main.php.net/note/reject/126769 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#217498) next »