wp_convert_hr_to_bytes() WordPress Function

The wp_convert_hr_to_bytes() function is used to convert a given value in human readable form into the number of bytes.

wp_convert_hr_to_bytes( string $value ) #

Converts a shorthand byte value to an integer byte value.


Parameters

$value

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


Top ↑

Return

(int) An integer byte value.


Top ↑

Source

File: 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 );
}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Moved from media.php to load.php.
2.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.