Created
January 27, 2018 14:10
-
-
Save jcicero518/d018dc243d51d019b1e05747ef170584 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
** | |
* Parse file size | |
* | |
* @param string $size File size | |
* @param string $default Default size | |
* @return string | |
*/ | |
function ai1wm_parse_size( $size, $default = null ) { | |
$suffixes = array( | |
'' => 1, | |
'k' => 1000, | |
'm' => 1000000, | |
'g' => 1000000000, | |
); | |
// Parse size format | |
if ( preg_match( '/([0-9]+)\s*(k|m|g)?(b?(ytes?)?)/i', $size, $match ) ) { | |
return $match[1] * $suffixes[ strtolower( $match[2] ) ]; | |
} | |
return $default; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment