API16

JUtility/return bytes: Difference between revisions

From Joomla! Documentation

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...
 
m clean up
Line 2: Line 2:
Return the byte value of a particular string  
Return the byte value of a particular string  


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JUtility/return_bytes|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JUtility/return_bytes}}
 
{{subst:Description:JUtility/return_bytes}}


===Syntax===
===Syntax===
Line 49: Line 47:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JUtility/return_bytes|Edit See Also]]<nowiki>]</nowiki>
{{subst:SeeAlso:JUtility/return_bytes}}
</span>
{{SeeAlso:JUtility/return_bytes}}


===Examples===
===Examples===

Revision as of 14:37, 24 March 2017

Description

Return the byte value of a particular string


{{subst:Description:JUtility/return_bytes}}

Syntax

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

Returns

int size in bytes

Defined in

libraries/joomla/utilities/utility.php

Importing

jimport( 'joomla.utilities.utility' );

Source Body

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;
}


{{subst:SeeAlso:JUtility/return_bytes}}

Examples

<CodeExamplesForm />