3v4l.org

run code in 300+ PHP versions simultaneously
<?php class MoneyHelper { public function getAmount($money) { $cleanString = preg_replace('/[^\d.,-]/', '', $money); $onlyNumbersString = preg_replace('/[^\d-]/', '', $money); $separatorsCountToBeErased = strlen($cleanString) - strlen($onlyNumbersString) - 1; $stringWithCommaOrDot = preg_replace('/[,.]/', '', $cleanString, $separatorsCountToBeErased); $removedThousandSeparator = preg_replace('/[.,](?=\d{3,}$)/', '', $stringWithCommaOrDot); //return (float) str_replace(',', '.', $removedThousandSeparator); return [ 'cleanString' => $cleanString, 'onlyNumbersString' => $onlyNumbersString, 'separatorsCountToBeErased' => $separatorsCountToBeErased, 'stringWithCommaOrDot' => $stringWithCommaOrDot, 'removedThousandSeparator' => $removedThousandSeparator, 'result' => (float) str_replace(',', '.', $removedThousandSeparator) ]; } } $obj = new MoneyHelper; echo var_dump($obj->getAmount('-200.000,54')) ;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bTW84
function name:  (null)
number of ops:  11
compiled vars:  !0 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   NEW                                              $1      'MoneyHelper'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   31     3        INIT_FCALL                                               'var_dump'
          4        INIT_METHOD_CALL                                         !0, 'getAmount'
          5        SEND_VAL_EX                                              '-200.000%2C54'
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                         $5      
          9        ECHO                                                     $5
         10      > RETURN                                                   1

Class MoneyHelper:
Function getamount:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bTW84
function name:  getAmount
number of ops:  45
compiled vars:  !0 = $money, !1 = $cleanString, !2 = $onlyNumbersString, !3 = $separatorsCountToBeErased, !4 = $stringWithCommaOrDot, !5 = $removedThousandSeparator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5B%5E%5Cd.%2C-%5D%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !1, $6
    7     7        INIT_FCALL                                               'preg_replace'
          8        SEND_VAL                                                 '%2F%5B%5E%5Cd-%5D%2F'
          9        SEND_VAL                                                 ''
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $8      
         12        ASSIGN                                                   !2, $8
    9    13        STRLEN                                           ~10     !1
         14        STRLEN                                           ~11     !2
         15        SUB                                              ~12     ~10, ~11
         16        SUB                                              ~13     ~12, 1
         17        ASSIGN                                                   !3, ~13
   11    18        INIT_FCALL                                               'preg_replace'
         19        SEND_VAL                                                 '%2F%5B%2C.%5D%2F'
         20        SEND_VAL                                                 ''
         21        SEND_VAR                                                 !1
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                         $15     
         24        ASSIGN                                                   !4, $15
   12    25        INIT_FCALL                                               'preg_replace'
         26        SEND_VAL                                                 '%2F%5B.%2C%5D%28%3F%3D%5Cd%7B3%2C%7D%24%29%2F'
         27        SEND_VAL                                                 ''
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $17     
         30        ASSIGN                                                   !5, $17
   17    31        INIT_ARRAY                                       ~19     !1, 'cleanString'
   18    32        ADD_ARRAY_ELEMENT                                ~19     !2, 'onlyNumbersString'
   19    33        ADD_ARRAY_ELEMENT                                ~19     !3, 'separatorsCountToBeErased'
   20    34        ADD_ARRAY_ELEMENT                                ~19     !4, 'stringWithCommaOrDot'
   21    35        ADD_ARRAY_ELEMENT                                ~19     !5, 'removedThousandSeparator'
   22    36        INIT_FCALL                                               'str_replace'
         37        SEND_VAL                                                 '%2C'
         38        SEND_VAL                                                 '.'
         39        SEND_VAR                                                 !5
         40        DO_ICALL                                         $20     
         41        CAST                                          5  ~21     $20
         42        ADD_ARRAY_ELEMENT                                ~19     ~21, 'result'
         43      > RETURN                                                   ~19
   26    44*     > RETURN                                                   null

End of function getamount

End of class MoneyHelper.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.15 ms | 1405 KiB | 19 Q