3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pattern = "~([^\d.,]|[.,](?!\d{2}$))|(,)~m"; $strings = [ "2.578,20", "2 354,20", "234", "234,256.20", "234,205", "246 548", "244'056", "26'155.25", "12,20", "13.33", ]; foreach ($strings as $string) { echo preg_replace_callback($pattern, function ($matches) { if (isset($matches[2])) return "."; if (isset($matches[1])) return ""; }, $string) . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/VBV00
function name:  (null)
number of ops:  15
compiled vars:  !0 = $pattern, !1 = $strings, !2 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7E%28%5B%5E%5Cd.%2C%5D%7C%5B.%2C%5D%28%3F%21%5Cd%7B2%7D%24%29%29%7C%28%2C%29%7Em'
    4     1        ASSIGN                                                   !1, <array>
   17     2      > FE_RESET_R                                       $5      !1, ->13
          3    > > FE_FETCH_R                                               $5, !2, ->13
   18     4    >   INIT_FCALL                                               'preg_replace_callback'
          5        SEND_VAR                                                 !0
          6        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
   21     7        SEND_VAL                                                 ~6
          8        SEND_VAR                                                 !2
   18     9        DO_ICALL                                         $7      
   21    10        CONCAT                                           ~8      $7, '%0A'
         11        ECHO                                                     ~8
   17    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $5
   22    14      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VBV00
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
   19     1        ISSET_ISEMPTY_DIM_OBJ                         0          !0, 2
          2      > JMPZ                                                     ~1, ->4
          3    > > RETURN                                                   '.'
   20     4    >   ISSET_ISEMPTY_DIM_OBJ                         0          !0, 1
          5      > JMPZ                                                     ~2, ->7
          6    > > RETURN                                                   ''
   21     7    > > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.18 ms | 1006 KiB | 14 Q