php convert mb to bytes

Solutions on MaxInterview for php convert mb to bytes by the best coders in the world

showing results for - "php convert mb to bytes"
Emely
11 Sep 2020
1function toByteSize($p_sFormatted) {
2    $aUnits = array('B'=>0, 'KB'=>1, 'MB'=>2, 'GB'=>3, 'TB'=>4, 'PB'=>5, 'EB'=>6, 'ZB'=>7, 'YB'=>8);
3    $sUnit = strtoupper(trim(substr($p_sFormatted, -2)));
4    if (intval($sUnit) !== 0) {
5        $sUnit = 'B';
6    }
7    if (!in_array($sUnit, array_keys($aUnits))) {
8        return false;
9    }
10    $iUnits = trim(substr($p_sFormatted, 0, strlen($p_sFormatted) - 2));
11    if (!intval($iUnits) == $iUnits) {
12        return false;
13    }
14    return $iUnits * pow(1024, $aUnits[$sUnit]);
15}