PMA\libraries\Util::extractValueFromFormattedSize PHP Method

extractValueFromFormattedSize() public static method

Returns the number of bytes when a formatted size is given
public static extractValueFromFormattedSize ( string $formatted_size ) : integer
$formatted_size string the size expression (for example 8MB)
return integer The numerical part of the expression (for example 8)
    public static function extractValueFromFormattedSize($formatted_size)
    {
        $return_value = -1;
        if (preg_match('/^[0-9]+GB$/', $formatted_size)) {
            $return_value = mb_substr($formatted_size, 0, -2) * pow(1024, 3);
        } elseif (preg_match('/^[0-9]+MB$/', $formatted_size)) {
            $return_value = mb_substr($formatted_size, 0, -2) * pow(1024, 2);
        } elseif (preg_match('/^[0-9]+K$/', $formatted_size)) {
            $return_value = mb_substr($formatted_size, 0, -1) * pow(1024, 1);
        }
        return $return_value;
    }

Usage Example

コード例 #1
0
 /**
  * returns the pbxt engine specific handling for
  * PMA_ENGINE_DETAILS_TYPE_SIZE variables.
  *
  * @param string $formatted_size the size expression (for example 8MB)
  *
  * @return string the formatted value and its unit
  */
 public function resolveTypeSize($formatted_size)
 {
     if (preg_match('/^[0-9]+[a-zA-Z]+$/', $formatted_size)) {
         $value = PMA\libraries\Util::extractValueFromFormattedSize($formatted_size);
     } else {
         $value = $formatted_size;
     }
     return PMA\libraries\Util::formatByteDown($value);
 }
Util