number_helper.php

Go to the documentation of this file.
00001 <?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
00002 /**
00003  * CodeIgniter
00004  *
00005  * An open source application development framework for PHP 4.3.2 or newer
00006  *
00007  * @package             CodeIgniter
00008  * @author              ExpressionEngine Dev Team
00009  * @copyright   Copyright (c) 2006, EllisLab, Inc.
00010  * @license             http://codeigniter.com/user_guide/license.html
00011  * @link                http://codeigniter.com
00012  * @since               Version 1.0
00013  * @filesource
00014  */
00015 
00016 // ------------------------------------------------------------------------
00017 
00018 /**
00019  * CodeIgniter Number Helpers
00020  *
00021  * @package             CodeIgniter
00022  * @subpackage  Helpers
00023  * @category    Helpers
00024  * @author              ExpressionEngine Dev Team
00025  * @link                http://codeigniter.com/user_guide/helpers/number_helper.html
00026  */
00027 
00028 // ------------------------------------------------------------------------
00029 
00030 /**
00031  * Formats a numbers as bytes, based on size, and adds the appropriate suffix
00032  *
00033  * @access      public
00034  * @param       mixed   // will be cast as int
00035  * @return      string
00036  */
00037 if ( ! function_exists('byte_format'))
00038 {
00039         function byte_format($num)
00040         {
00041                 $CI =& get_instance();
00042                 $CI->lang->load('number');
00043 
00044                 if ($num >= 1000000000000) 
00045                 {
00046                         $num = round($num/1099511627776)/10;
00047                         $unit  = $CI->lang->line('terabyte_abbr');
00048                 }
00049                 elseif ($num >= 1000000000) 
00050                 {
00051                         $num = round($num/107374182)/10;
00052                         $unit  = $CI->lang->line('gigabyte_abbr');
00053                 }
00054                 elseif ($num >= 1000000) 
00055                 {
00056                         $num = round($num/104857)/10;
00057                         $unit  = $CI->lang->line('megabyte_abbr');
00058                 }
00059                 elseif ($num >= 1000) 
00060                 {
00061                         $num = round($num/102)/10;
00062                         $unit  = $CI->lang->line('kilobyte_abbr');
00063                 }
00064                 else
00065                 {
00066                         $unit = $CI->lang->line('bytes');
00067                         return number_format($num).' '.$unit;
00068                 }
00069 
00070                 return number_format($num, 1).' '.$unit;
00071         }       
00072 }
00073 
00074 /* End of file number_helper.php */
00075 /* Location: ./system/helpers/number_helper.php */