src/Koldy/Convert.php
public static function stringToBytes(string $string): int
    {
        $original = trim($string);
        $number = (int)$original;

        if ($number === $original || $number === 0) {
            return $number;
        } else {
            $char = strtoupper(substr($original, -1, 1));
            switch ($char) {
                case 'K': // KILO
                    return $number * 1024;
                    break;

                case 'M': // MEGA
                    return $number * pow(1024, 2);
                    break;

                case 'G': // GIGA
                    return $number * pow(1024, 3);
                    break;

                case 'T': // TERA
                    return $number * pow(1024, 4);
                    break;

                case 'P': // PETA
                    return $number * pow(1024, 5);
                    break;

                case 'E': // EXA
                    return $number * pow(1024, 6);
                    break;

                default:
                    throw new ConvertException('Not implemented sizes greater than exabytes');
                    break;
            }
        }
    }
public static function stringToBytes(string $string): int
    {
        $original = trim($string);
        $number = (int)$original;

        if ($number === $original || $number === 0) {
            return $number;
        } else {
            $char = strtoupper(substr($original, -1, 1));
            switch ($char) {
                case 'K': // KILO
                    return $number * 1024;
                    break;

                case 'M': // MEGA
                    return $number * pow(1024, 2);
                    break;

                case 'G': // GIGA
                    return $number * pow(1024, 3);
                    break;

                case 'T': // TERA
                    return $number * pow(1024, 4);
                    break;

                case 'P': // PETA
                    return $number * pow(1024, 5);
                    break;

                case 'E': // EXA
                    return $number * pow(1024, 6);
                    break;

                default:
                    throw new ConvertException('Not implemented sizes greater than exabytes');
                    break;
            }
        }
    }
public static function stringToBytes ( string $ string ) : int { $ original = trim ( $ string ) ; $ number = ( int ) $ original ; if ( $ number === $ original || $ number === 0 ) { return $ number ; } else { $ char = strtoupper ( substr ( $ original , - 1 , 1 ) ) ; switch ( $ char ) { case 'K' : // KILO return $ number * 1024 ; break ; case 'M' : // MEGA return $ number * pow ( 1024 , 2 ) ; break ; case 'G' : // GIGA return $ number * pow ( 1024 , 3 ) ; break ; case 'T' : // TERA return $ number * pow ( 1024 , 4 ) ; break ; case 'P' : // PETA return $ number * pow ( 1024 , 5 ) ; break ; case 'E' : // EXA return $ number * pow ( 1024 , 6 ) ; break ; default : throw new ConvertException ( 'Not implemented sizes greater than exabytes' ) ; break ; } } }
Get the number of bytes from string

@param string $string

@return int
@throws ConvertException
@example 1M will return 1048576

@link https://koldy.net/framework/docs/2.0/converters.md#stringtobytes
Get the number of bytes from string