3v4l.org

run code in 300+ PHP versions simultaneously
<?php function formatPhone($n) { //Remove any parentheses and the numbers they contain: $n = preg_replace("/\([0-9]+?\)/", "", $n); //Strip spaces and non-numeric characters: $n = preg_replace("/[^0-9]/", "", $n); //Strip out leading zeros: $n = ltrim($n, '0'); //Strip out leading +: $n = ltrim($n, '+'); if(strlen($n) <= 10) { if(substr( $n, 0, 2 ) === "39") return preg_replace('/^39/','+3939', $n); else return '+39' . $n; } else if(strlen($n) > 10){ return preg_replace('/^(?:\+?39|0)?/','+39', $n); } } echo formatPhone("335123456") . "\n"; echo formatPhone("39335123456") . "\n"; echo formatPhone("+39335123456") . "\n"; echo formatPhone("0039335123456") . "\n"; echo formatPhone("039335123456") . "\n"; echo formatPhone("3931234567") . "\n"; echo formatPhone("+39335123456") . "\n"; echo formatPhone("399123456") . "\n"; echo formatPhone("39399123456") . "\n"; echo formatPhone("+39399123456");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UDOrt
function name:  (null)
number of ops:  50
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   INIT_FCALL                                               'formatphone'
          1        SEND_VAL                                                 '335123456'
          2        DO_FCALL                                      0  $0      
          3        CONCAT                                           ~1      $0, '%0A'
          4        ECHO                                                     ~1
   27     5        INIT_FCALL                                               'formatphone'
          6        SEND_VAL                                                 '39335123456'
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%0A'
          9        ECHO                                                     ~3
   28    10        INIT_FCALL                                               'formatphone'
         11        SEND_VAL                                                 '%2B39335123456'
         12        DO_FCALL                                      0  $4      
         13        CONCAT                                           ~5      $4, '%0A'
         14        ECHO                                                     ~5
   29    15        INIT_FCALL                                               'formatphone'
         16        SEND_VAL                                                 '0039335123456'
         17        DO_FCALL                                      0  $6      
         18        CONCAT                                           ~7      $6, '%0A'
         19        ECHO                                                     ~7
   30    20        INIT_FCALL                                               'formatphone'
         21        SEND_VAL                                                 '039335123456'
         22        DO_FCALL                                      0  $8      
         23        CONCAT                                           ~9      $8, '%0A'
         24        ECHO                                                     ~9
   31    25        INIT_FCALL                                               'formatphone'
         26        SEND_VAL                                                 '3931234567'
         27        DO_FCALL                                      0  $10     
         28        CONCAT                                           ~11     $10, '%0A'
         29        ECHO                                                     ~11
   32    30        INIT_FCALL                                               'formatphone'
         31        SEND_VAL                                                 '%2B39335123456'
         32        DO_FCALL                                      0  $12     
         33        CONCAT                                           ~13     $12, '%0A'
         34        ECHO                                                     ~13
   33    35        INIT_FCALL                                               'formatphone'
         36        SEND_VAL                                                 '399123456'
         37        DO_FCALL                                      0  $14     
         38        CONCAT                                           ~15     $14, '%0A'
         39        ECHO                                                     ~15
   34    40        INIT_FCALL                                               'formatphone'
         41        SEND_VAL                                                 '39399123456'
         42        DO_FCALL                                      0  $16     
         43        CONCAT                                           ~17     $16, '%0A'
         44        ECHO                                                     ~17
   35    45        INIT_FCALL                                               'formatphone'
         46        SEND_VAL                                                 '%2B39399123456'
         47        DO_FCALL                                      0  $18     
         48        ECHO                                                     $18
         49      > RETURN                                                   1

Function formatphone:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 43
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 40
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 52
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UDOrt
function name:  formatPhone
number of ops:  53
compiled vars:  !0 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_replace'
          2        SEND_VAL                                                 '%2F%5C%28%5B0-9%5D%2B%3F%5C%29%2F'
          3        SEND_VAL                                                 ''
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $1      
          6        ASSIGN                                                   !0, $1
    7     7        INIT_FCALL                                               'preg_replace'
          8        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2F'
          9        SEND_VAL                                                 ''
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $3      
         12        ASSIGN                                                   !0, $3
    9    13        INIT_FCALL                                               'ltrim'
         14        SEND_VAR                                                 !0
         15        SEND_VAL                                                 '0'
         16        DO_ICALL                                         $5      
         17        ASSIGN                                                   !0, $5
   11    18        INIT_FCALL                                               'ltrim'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 '%2B'
         21        DO_ICALL                                         $7      
         22        ASSIGN                                                   !0, $7
   14    23        STRLEN                                           ~9      !0
         24        IS_SMALLER_OR_EQUAL                                      ~9, 10
         25      > JMPZ                                                     ~10, ->43
   16    26    >   INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !0
         28        SEND_VAL                                                 0
         29        SEND_VAL                                                 2
         30        DO_ICALL                                         $11     
         31        IS_IDENTICAL                                             $11, '39'
         32      > JMPZ                                                     ~12, ->40
   17    33    >   INIT_FCALL                                               'preg_replace'
         34        SEND_VAL                                                 '%2F%5E39%2F'
         35        SEND_VAL                                                 '%2B3939'
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $13     
         38      > RETURN                                                   $13
         39*       JMP                                                      ->42
   19    40    >   CONCAT                                           ~14     '%2B39', !0
         41      > RETURN                                                   ~14
         42*       JMP                                                      ->52
   20    43    >   STRLEN                                           ~15     !0
         44        IS_SMALLER                                               10, ~15
         45      > JMPZ                                                     ~16, ->52
   21    46    >   INIT_FCALL                                               'preg_replace'
         47        SEND_VAL                                                 '%2F%5E%28%3F%3A%5C%2B%3F39%7C0%29%3F%2F'
         48        SEND_VAL                                                 '%2B39'
         49        SEND_VAR                                                 !0
         50        DO_ICALL                                         $17     
         51      > RETURN                                                   $17
   24    52    > > RETURN                                                   null

End of function formatphone

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.38 ms | 1398 KiB | 29 Q