Last active
May 13, 2019 20:25
-
-
Save thbighead/77fc1efab03bff2d23af96bfb5b1b589 to your computer and use it in GitHub Desktop.
Function to cast the shorthand memory notation value to bytes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts shorthand memory notation value to bytes | |
* From http://php.net/manual/en/function.ini-get.php | |
* | |
* @param string $val memory size shorthand notation string | |
* @return int|string | |
*/ | |
function return_bytes($val) | |
{ | |
$val = trim($val); | |
$last = strtolower($val[strlen($val) - 1]); | |
$val = substr($val, 0, -1); | |
switch ($last) { | |
// The 'G' modifier is available since PHP 5.1.0 | |
case 'g': | |
$val *= 1024; | |
case 'm': | |
$val *= 1024; | |
case 'k': | |
$val *= 1024; | |
} | |
return $val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment