このエントリーをはてなブックマークに追加

更新日: 2016年2月25日

実行時間: 0.0091

数字ヘルパー

 数字ヘルパーは「 system/helper/number_helper.php 」ファイルで、数値をデータサイズのバイト単位で取得する 関数が定義されています。

数字ヘルパーのロード

 「 CI_Loader 」クラスの「 helper() 」メソッドでロードします。

    $this->load->helper('number');

数字ヘルパーの関数

byte_format($num, $precision = 1)

 第一引数に、バイト単位に変換したい数値を指定します。
 第二引数は、小数点以下の桁数を指定します。

    $this->load->helper('number');

    echo byte_format(9876543210, 2);
    // 9.20 GB

 「 byte_format() 」関数は、実行時に言語ファイルをロードして言語設定されたバイト単位の文字列を
利用することができます。
 言語定義ファイルは「 number_lang.php 」となります。

    • application/language/japanese/number_lang.php
    <?php
    $lang['terabyte_abbr'] = "テラバイト";
    $lang['gigabyte_abbr'] = "ギガバイト";
    $lang['megabyte_abbr'] = "メガバイト";
    $lang['kilobyte_abbr'] = "キロバイト";
    $lang['bytes'] = "バイト";
    $this->config->set_item('language', 'japanese');
    $this->load->helper('number');

    echo byte_format(9876543210);
    // 9.2 ギガバイト