wp_convert_hr_to_bytes

Converts a shorthand byte value to an integer byte value.

Description

(int) wp_convert_hr_to_bytes( (string) $value ); 

Returns (int)

An integer byte value.

Parameters (1)

0. $value (string)
A (PHP ini) byte value, either shorthand or ordinary.

Usage

  1. if ( !function_exists( 'wp_convert_hr_to_bytes' ) ) { 
  2. require_once ABSPATH . WPINC . '/load.php'; 
  3.  
  4. // A (PHP ini) byte value, either shorthand or ordinary. 
  5. $value = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_convert_hr_to_bytes($value); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/load.php  
  1. function wp_convert_hr_to_bytes( $value ) { 
  2. $value = strtolower( trim( $value ) ); 
  3. $bytes = (int) $value; 
  4.  
  5. if ( false !== strpos( $value, 'g' ) ) { 
  6. $bytes *= GB_IN_BYTES
  7. } elseif ( false !== strpos( $value, 'm' ) ) { 
  8. $bytes *= MB_IN_BYTES
  9. } elseif ( false !== strpos( $value, 'k' ) ) { 
  10. $bytes *= KB_IN_BYTES
  11.  
  12. // Deal with large (float) values which run into the maximum integer size. 
  13. return min( $bytes, PHP_INT_MAX );