API16

JUtility/return bytes

From Joomla! Documentation

< API16:JUtility
Revision as of 17:56, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Return the byte value of a particular string <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JUtility/return_bytes|Edit Descripton...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Return the byte value of a particular string

[Edit Descripton]

Template:Description:JUtility/return bytes

Syntax[edit]

return_bytes($val)
Parameter Name Default Value Description
$val String optionally with G, M or K suffix

Returns[edit]

int size in bytes

Defined in[edit]

libraries/joomla/utilities/utility.php

Importing[edit]

jimport( 'joomla.utilities.utility' );

Source Body[edit]

function return_bytes($val) {
        $val = trim($val);
        $last = strtolower($val{strlen($val)-1});
        switch($last) {
                // The 'G' modifier is available since PHP 5.1.0
                case 'g':
                        $val *= 1024;
                case 'm':
                        $val *= 1024;
                case 'k':
                        $val *= 1024;
        }

        return $val;
}

[Edit See Also] Template:SeeAlso:JUtility/return bytes

Examples[edit]

<CodeExamplesForm />