3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * convertBytes * * Convert bytes into human readable form with rounding * * @name convertBytes * @access public * @param integer $bytes * @param integer $decimals = 2 * @desc Convert bytes into human readable form with rounding * @return string */ function convertBytes($bytes, $decimals = 2) { $suffixes = 'BKMGTP'; $factor = floor((strlen($bytes) - 1) / 3); return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$suffixes[$factor]; } echo PHP_INT_SIZE . "\n"; echo convertBytes(1500)."\n"; echo convertBytes(1500*1000)."\n"; echo convertBytes(1500*1000*1000)."\n"; echo convertBytes(1500*1000*1000*1000)."\n"; echo convertBytes(1500*1000*1000*1000*1000)."\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rCeaP
function name:  (null)
number of ops:  27
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ECHO                                                     '8%0A'
   23     1        INIT_FCALL                                               'convertbytes'
          2        SEND_VAL                                                 1500
          3        DO_FCALL                                      0  $0      
          4        CONCAT                                           ~1      $0, '%0A'
          5        ECHO                                                     ~1
   24     6        INIT_FCALL                                               'convertbytes'
          7        SEND_VAL                                                 1500000
          8        DO_FCALL                                      0  $2      
          9        CONCAT                                           ~3      $2, '%0A'
         10        ECHO                                                     ~3
   25    11        INIT_FCALL                                               'convertbytes'
         12        SEND_VAL                                                 1500000000
         13        DO_FCALL                                      0  $4      
         14        CONCAT                                           ~5      $4, '%0A'
         15        ECHO                                                     ~5
   26    16        INIT_FCALL                                               'convertbytes'
         17        SEND_VAL                                                 1500000000000
         18        DO_FCALL                                      0  $6      
         19        CONCAT                                           ~7      $6, '%0A'
         20        ECHO                                                     ~7
   27    21        INIT_FCALL                                               'convertbytes'
         22        SEND_VAL                                                 1500000000000000
         23        DO_FCALL                                      0  $8      
         24        CONCAT                                           ~9      $8, '%0A'
         25        ECHO                                                     ~9
         26      > RETURN                                                   1

Function convertbytes:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rCeaP
function name:  convertBytes
number of ops:  28
compiled vars:  !0 = $bytes, !1 = $decimals, !2 = $suffixes, !3 = $factor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
   18     2        ASSIGN                                                   !2, 'BKMGTP'
   19     3        INIT_FCALL                                               'floor'
          4        STRLEN                                           ~5      !0
          5        SUB                                              ~6      ~5, 1
          6        DIV                                              ~7      ~6, 3
          7        SEND_VAL                                                 ~7
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !3, $8
   20    10        INIT_FCALL                                               'sprintf'
         11        ROPE_INIT                                     3  ~11     '%25.'
         12        ROPE_ADD                                      1  ~11     ~11, !1
         13        ROPE_END                                      2  ~10     ~11, 'f'
         14        SEND_VAL                                                 ~10
         15        INIT_FCALL                                               'pow'
         16        SEND_VAL                                                 1024
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $13     
         19        DIV                                              ~14     !0, $13
         20        SEND_VAL                                                 ~14
         21        DO_ICALL                                         $15     
         22        BEGIN_SILENCE                                    ~16     
         23        FETCH_DIM_R                                      ~17     !2, !3
         24        END_SILENCE                                              ~16
         25        CONCAT                                           ~18     $15, ~17
         26      > RETURN                                                   ~18
   21    27*     > RETURN                                                   null

End of function convertbytes

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.84 ms | 1403 KiB | 24 Q