3v4l.org

run code in 500+ 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:  33
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        FRAMELESS_ICALL_3                preg_replace        ~6      '%2F%5B%5E%5Cd.%2C-%5D%2F', ''
          2        OP_DATA                                                      !0
          3        ASSIGN                                                       !1, ~6
    7     4        FRAMELESS_ICALL_3                preg_replace        ~8      '%2F%5B%5E%5Cd-%5D%2F', ''
          5        OP_DATA                                                      !0
          6        ASSIGN                                                       !2, ~8
    9     7        STRLEN                                               ~10     !1
          8        STRLEN                                               ~11     !2
          9        SUB                                                  ~12     ~10, ~11
         10        SUB                                                  ~13     ~12, 1
         11        ASSIGN                                                       !3, ~13
   11    12        INIT_FCALL                                                   'preg_replace'
         13        SEND_VAL                                                     '%2F%5B%2C.%5D%2F'
         14        SEND_VAL                                                     ''
         15        SEND_VAR                                                     !1
         16        SEND_VAR                                                     !3
         17        DO_ICALL                                             $15     
         18        ASSIGN                                                       !4, $15
   12    19        FRAMELESS_ICALL_3                preg_replace        ~17     '%2F%5B.%2C%5D%28%3F%3D%5Cd%7B3%2C%7D%24%29%2F', ''
         20        OP_DATA                                                      !4
         21        ASSIGN                                                       !5, ~17
   17    22        INIT_ARRAY                                           ~19     !1, 'cleanString'
   18    23        ADD_ARRAY_ELEMENT                                    ~19     !2, 'onlyNumbersString'
   19    24        ADD_ARRAY_ELEMENT                                    ~19     !3, 'separatorsCountToBeErased'
   20    25        ADD_ARRAY_ELEMENT                                    ~19     !4, 'stringWithCommaOrDot'
   21    26        ADD_ARRAY_ELEMENT                                    ~19     !5, 'removedThousandSeparator'
   22    27        FRAMELESS_ICALL_3                str_replace         ~20     '%2C', '.'
         28        OP_DATA                                                      !5
         29        CAST                                              5  ~21     ~20
         30        ADD_ARRAY_ELEMENT                                    ~19     ~21, 'result'
         31      > RETURN                                                       ~19
   26    32*     > RETURN                                                       null

End of function getamount

End of class MoneyHelper.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
228.34 ms | 2707 KiB | 15 Q