WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Difference between revisions of "Function Reference/size format"

m (added link to Japanese translation)
(Added example and description)
 
Line 5: Line 5:
   
 
==Description==
 
==Description==
  +
Convert a given number of bytes into a human readable format, using the largest unit the bytes will fit into.
   
 
==Parameters==
 
==Parameters==
Line 14: Line 15:
   
 
== Usage ==
 
== Usage ==
%%% <?php ?> %%%
+
%%% <?php $size_to_display = size_format(1024); %%%
   
 
==Example==
 
==Example==
Description text
+
Display the size of a file
 
<pre>
 
<pre>
Example code
+
$file_size = 1229; // filesize in bytes
  +
echo size_format($file_size, 2); // displays "1.20 kB"
 
</pre>
 
</pre>
  +
   
 
==Change Log==
 
==Change Log==

Latest revision as of 17:39, 6 August 2013

Description

Convert a given number of bytes into a human readable format, using the largest unit the bytes will fit into.

Parameters

$bytes
(mixed) (required) Number of bytes. Note max integer size for integers. Accepts int or string
Default: None
$decimals
(int) (optional) Precision of number of decimal places. Deprecated.
Default: 0

Return

boolean or string. False on failure. Number string on success.

Usage

 <?php $size_to_display size_format(1024); 

Example

Display the size of a file

$file_size = 1229; // filesize in bytes
echo size_format($file_size, 2); // displays "1.20 kB"


Change Log

Source File

size_format() is located in wp-includes/functions.php.

Related

Function ref links

This article is marked as in need of editing. You can help Codex by editing it.