3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getValorDecimal($linhaDados, $posicaoInicial, $tamanhoCampo, $decimal = 0) { $retorno = ""; $retorno = substr($linhaDados,$posicaoInicial-1 , $tamanhoCampo ); $retorno = trim($retorno); $retorno = str_replace(".","", $retorno); $retorno = str_replace(",",".", $retorno); if ($retorno != "") { $retorno = ltrim($retorno,'0'); if ($retorno == '') { $retorno = '0'; } if ($retorno != 0 && $decimal != 0) { $divisor = str_pad('1', $decimal + 1, '0'); $retorno = round($retorno / $divisor , $decimal); } } return $retorno; } function getValor2DecAlignRight($dado, $size, $completa = "0"){ $new = ""; if ($dado != ''){ $new= number_format($dado,2,'',''); $new = str_pad(substr($new,0,$size), $size, $completa, STR_PAD_LEFT); }else{ $new = str_pad(substr($new,0,$size), $size, $completa, STR_PAD_LEFT); } return $new; } $currentLine = '000000004575030'; $valor = getValorDecimal($currentLine, 1, 15, 2); var_dump( $valor ); $valor = getValor2DecAlignRight((string) $valor, 15); var_dump( $valor );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k1Yhk
function name:  (null)
number of ops:  21
compiled vars:  !0 = $currentLine, !1 = $valor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, '000000004575030'
   35     1        INIT_FCALL                                               'getvalordecimal'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 1
          4        SEND_VAL                                                 15
          5        SEND_VAL                                                 2
          6        DO_FCALL                                      0  $3      
          7        ASSIGN                                                   !1, $3
   36     8        INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
   38    11        INIT_FCALL                                               'getvalor2decalignright'
         12        CAST                                          6  ~6      !1
         13        SEND_VAL                                                 ~6
         14        SEND_VAL                                                 15
         15        DO_FCALL                                      0  $7      
         16        ASSIGN                                                   !1, $7
   39    17        INIT_FCALL                                               'var_dump'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function getvalordecimal:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 56
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 38
Branch analysis from position: 37
2 jumps found. (Code = 46) Position 1 = 40, Position 2 = 42
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 56
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
Branch analysis from position: 42
Branch analysis from position: 38
Branch analysis from position: 56
filename:       /in/k1Yhk
function name:  getValorDecimal
number of ops:  58
compiled vars:  !0 = $linhaDados, !1 = $posicaoInicial, !2 = $tamanhoCampo, !3 = $decimal, !4 = $retorno, !5 = $divisor
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV_INIT                                        !3      0
    4     4        ASSIGN                                                   !4, ''
    5     5        INIT_FCALL                                               'substr'
          6        SEND_VAR                                                 !0
          7        SUB                                              ~7      !1, 1
          8        SEND_VAL                                                 ~7
          9        SEND_VAR                                                 !2
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !4, $8
    6    12        INIT_FCALL                                               'trim'
         13        SEND_VAR                                                 !4
         14        DO_ICALL                                         $10     
         15        ASSIGN                                                   !4, $10
    7    16        INIT_FCALL                                               'str_replace'
         17        SEND_VAL                                                 '.'
         18        SEND_VAL                                                 ''
         19        SEND_VAR                                                 !4
         20        DO_ICALL                                         $12     
         21        ASSIGN                                                   !4, $12
    8    22        INIT_FCALL                                               'str_replace'
         23        SEND_VAL                                                 '%2C'
         24        SEND_VAL                                                 '.'
         25        SEND_VAR                                                 !4
         26        DO_ICALL                                         $14     
         27        ASSIGN                                                   !4, $14
    9    28        IS_NOT_EQUAL                                             !4, ''
         29      > JMPZ                                                     ~16, ->56
   10    30    >   INIT_FCALL                                               'ltrim'
         31        SEND_VAR                                                 !4
         32        SEND_VAL                                                 '0'
         33        DO_ICALL                                         $17     
         34        ASSIGN                                                   !4, $17
   11    35        IS_EQUAL                                                 !4, ''
         36      > JMPZ                                                     ~19, ->38
   12    37    >   ASSIGN                                                   !4, '0'
   14    38    >   IS_NOT_EQUAL                                     ~21     !4, 0
         39      > JMPZ_EX                                          ~21     ~21, ->42
         40    >   IS_NOT_EQUAL                                     ~22     !3, 0
         41        BOOL                                             ~21     ~22
         42    > > JMPZ                                                     ~21, ->56
   15    43    >   INIT_FCALL                                               'str_pad'
         44        SEND_VAL                                                 '1'
         45        ADD                                              ~23     !3, 1
         46        SEND_VAL                                                 ~23
         47        SEND_VAL                                                 '0'
         48        DO_ICALL                                         $24     
         49        ASSIGN                                                   !5, $24
   16    50        INIT_FCALL                                               'round'
         51        DIV                                              ~26     !4, !5
         52        SEND_VAL                                                 ~26
         53        SEND_VAR                                                 !3
         54        DO_ICALL                                         $27     
         55        ASSIGN                                                   !4, $27
   19    56    > > RETURN                                                   !4
   20    57*     > RETURN                                                   null

End of function getvalordecimal

Function getvalor2decalignright:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 26
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/k1Yhk
function name:  getValor2DecAlignRight
number of ops:  40
compiled vars:  !0 = $dado, !1 = $size, !2 = $completa, !3 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '0'
   23     3        ASSIGN                                                   !3, ''
   24     4        IS_NOT_EQUAL                                             !0, ''
          5      > JMPZ                                                     ~5, ->26
   25     6    >   INIT_FCALL                                               'number_format'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 2
          9        SEND_VAL                                                 ''
         10        SEND_VAL                                                 ''
         11        DO_ICALL                                         $6      
         12        ASSIGN                                                   !3, $6
   26    13        INIT_FCALL                                               'str_pad'
         14        INIT_FCALL                                               'substr'
         15        SEND_VAR                                                 !3
         16        SEND_VAL                                                 0
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $8      
         19        SEND_VAR                                                 $8
         20        SEND_VAR                                                 !1
         21        SEND_VAR                                                 !2
         22        SEND_VAL                                                 0
         23        DO_ICALL                                         $9      
         24        ASSIGN                                                   !3, $9
         25      > JMP                                                      ->38
   28    26    >   INIT_FCALL                                               'str_pad'
         27        INIT_FCALL                                               'substr'
         28        SEND_VAR                                                 !3
         29        SEND_VAL                                                 0
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                         $11     
         32        SEND_VAR                                                 $11
         33        SEND_VAR                                                 !1
         34        SEND_VAR                                                 !2
         35        SEND_VAL                                                 0
         36        DO_ICALL                                         $12     
         37        ASSIGN                                                   !3, $12
   30    38    > > RETURN                                                   !3
   31    39*     > RETURN                                                   null

End of function getvalor2decalignright

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.35 ms | 1407 KiB | 31 Q