3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ReformatPhoneNumber($number){ if( !preg_match('/^[0-9][0-9\- ]+[0-9]$/', $number) || // (strlen($number) > 12) || // (strlen($number) < 7) || (preg_match_all('/[0-9]/', $number) > 12 ) || (preg_match_all('/[0-9]/', $number) < 7 ) || (preg_match('/[ \-]{2,}/', $number)) ){ throw new \Exception('Invalid phone number'); } return trim(preg_replace('/[^0-9]/','',$number)); } echo ReformatPhoneNumber('012-345 69') ."\n"; foreach(array('012345', '-012345 678', '01203- 34566', '123456678875432','1234x567','1234567890123') as $invalid){ try { ReformatPhoneNumber($invalid); }catch(\Exception $e){ continue; } echo "ACCEPTED $invalid !!!!!!!!\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Found catch point at position: 11
Branch analysis from position: 11
2 jumps found. (Code = 107) Position 1 = 12, Position 2 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
filename:       /in/580K7
function name:  (null)
number of ops:  20
compiled vars:  !0 = $invalid, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                               'reformatphonenumber'
          1        SEND_VAL                                                 '012-345+69'
          2        DO_FCALL                                      0  $2      
          3        CONCAT                                           ~3      $2, '%0A'
          4        ECHO                                                     ~3
   19     5      > FE_RESET_R                                       $4      <array>, ->18
          6    > > FE_FETCH_R                                               $4, !0, ->18
   21     7    >   INIT_FCALL                                               'reformatphonenumber'
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0          
         10      > JMP                                                      ->13
   22    11  E > > CATCH                                       last         'Exception'
   23    12    > > JMP                                                      ->6
   26    13    >   ROPE_INIT                                     3  ~7      'ACCEPTED+'
         14        ROPE_ADD                                      1  ~7      ~7, !0
         15        ROPE_END                                      2  ~6      ~7, '+%21%21%21%21%21%21%21%21%0A'
         16        ECHO                                                     ~6
   19    17      > JMP                                                      ->6
         18    >   FE_FREE                                                  $4
   27    19      > RETURN                                                   1

Function reformatphonenumber:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 47) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
Branch analysis from position: 20
Branch analysis from position: 13
filename:       /in/580K7
function name:  ReformatPhoneNumber
number of ops:  41
compiled vars:  !0 = $number
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%5E%5B0-9%5D%5B0-9%5C-+%5D%2B%5B0-9%5D%24%2F'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5        BOOL_NOT                                         ~2      $1
          6      > JMPNZ_EX                                         ~2      ~2, ->13
    7     7    >   INIT_FCALL                                               'preg_match_all'
          8        SEND_VAL                                                 '%2F%5B0-9%5D%2F'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $3      
         11        IS_SMALLER                                       ~4      12, $3
         12        BOOL                                             ~2      ~4
         13    > > JMPNZ_EX                                         ~2      ~2, ->20
    8    14    >   INIT_FCALL                                               'preg_match_all'
         15        SEND_VAL                                                 '%2F%5B0-9%5D%2F'
         16        SEND_VAR                                                 !0
         17        DO_ICALL                                         $5      
         18        IS_SMALLER                                       ~6      $5, 7
         19        BOOL                                             ~2      ~6
         20    > > JMPNZ_EX                                         ~2      ~2, ->26
    9    21    >   INIT_FCALL                                               'preg_match'
         22        SEND_VAL                                                 '%2F%5B+%5C-%5D%7B2%2C%7D%2F'
         23        SEND_VAR                                                 !0
         24        DO_ICALL                                         $7      
         25        BOOL                                             ~2      $7
         26    > > JMPZ                                                     ~2, ->31
   11    27    >   NEW                                              $8      'Exception'
         28        SEND_VAL_EX                                              'Invalid+phone+number'
         29        DO_FCALL                                      0          
         30      > THROW                                         0          $8
   14    31    >   INIT_FCALL                                               'trim'
         32        INIT_FCALL                                               'preg_replace'
         33        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2F'
         34        SEND_VAL                                                 ''
         35        SEND_VAR                                                 !0
         36        DO_ICALL                                         $10     
         37        SEND_VAR                                                 $10
         38        DO_ICALL                                         $11     
         39      > RETURN                                                   $11
   15    40*     > RETURN                                                   null

End of function reformatphonenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.59 ms | 1406 KiB | 24 Q