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, $foo) > 12 ) || (preg_match_all('/[0-9]/', $number, $foo) < 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/1qbSk
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 = 14
Branch analysis from position: 7
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
2 jumps found. (Code = 47) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 33
Branch analysis from position: 29
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 22
Branch analysis from position: 14
filename:       /in/1qbSk
function name:  ReformatPhoneNumber
number of ops:  43
compiled vars:  !0 = $number, !1 = $foo
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                                         $2      
          5        BOOL_NOT                                         ~3      $2
          6      > JMPNZ_EX                                         ~3      ~3, ->14
    7     7    >   INIT_FCALL                                               'preg_match_all'
          8        SEND_VAL                                                 '%2F%5B0-9%5D%2F'
          9        SEND_VAR                                                 !0
         10        SEND_REF                                                 !1
         11        DO_ICALL                                         $4      
         12        IS_SMALLER                                       ~5      12, $4
         13        BOOL                                             ~3      ~5
         14    > > JMPNZ_EX                                         ~3      ~3, ->22
    8    15    >   INIT_FCALL                                               'preg_match_all'
         16        SEND_VAL                                                 '%2F%5B0-9%5D%2F'
         17        SEND_VAR                                                 !0
         18        SEND_REF                                                 !1
         19        DO_ICALL                                         $6      
         20        IS_SMALLER                                       ~7      $6, 7
         21        BOOL                                             ~3      ~7
         22    > > JMPNZ_EX                                         ~3      ~3, ->28
    9    23    >   INIT_FCALL                                               'preg_match'
         24        SEND_VAL                                                 '%2F%5B+%5C-%5D%7B2%2C%7D%2F'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $8      
         27        BOOL                                             ~3      $8
         28    > > JMPZ                                                     ~3, ->33
   11    29    >   NEW                                              $9      'Exception'
         30        SEND_VAL_EX                                              'Invalid+phone+number'
         31        DO_FCALL                                      0          
         32      > THROW                                         0          $9
   14    33    >   INIT_FCALL                                               'trim'
         34        INIT_FCALL                                               'preg_replace'
         35        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2F'
         36        SEND_VAL                                                 ''
         37        SEND_VAR                                                 !0
         38        DO_ICALL                                         $11     
         39        SEND_VAR                                                 $11
         40        DO_ICALL                                         $12     
         41      > RETURN                                                   $12
   15    42*     > RETURN                                                   null

End of function reformatphonenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.17 ms | 1403 KiB | 23 Q