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
if ( !function_exists( 'wp_convert_hr_to_bytes' ) ) { require_once ABSPATH . WPINC . '/load.php'; } // A (PHP ini) byte value, either shorthand or ordinary. $value = ''; // NOTICE! Understand what this does before running. $result = wp_convert_hr_to_bytes($value);
Defined (1)
The function is defined in the following location(s).
- /wp-includes/load.php
- function wp_convert_hr_to_bytes( $value ) {
- $value = strtolower( trim( $value ) );
- $bytes = (int) $value;
- if ( false !== strpos( $value, 'g' ) ) {
- $bytes *= GB_IN_BYTES;
- } elseif ( false !== strpos( $value, 'm' ) ) {
- $bytes *= MB_IN_BYTES;
- } elseif ( false !== strpos( $value, 'k' ) ) {
- $bytes *= KB_IN_BYTES;
- }
- // Deal with large (float) values which run into the maximum integer size.
- return min( $bytes, PHP_INT_MAX );
- }