3v4l.org

run code in 300+ PHP versions simultaneously
<?php function normalize_phone($phone) { preg_match("/((?:\\d+[\\s\\-\\(\\)+]+){5,})/", $phone, $matches); $normalized_phone = preg_replace("/[^0-9]+/", "", $matches[1]); if (substr($normalized_phone, 0, 1) === "7") $normalized_phone = "8" . substr($normalized_phone, 1); elseif (substr($normalized_phone, 0, 1) === "9") $normalized_phone = "8" . $normalized_phone; return $normalized_phone; } echo normalize_phone("10 тел +7 (916) 297-67-97 Александр Мартынов 10");
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l6PpZ
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   INIT_FCALL                                               'normalize_phone'
          1        SEND_VAL                                                 '10+%D1%82%D0%B5%D0%BB+%2B7+%28916%29+297-67-97+%D0%90%D0%BB%D0%B5%D0%BA%D1%81%D0%B0%D0%BD%D0%B4%D1%80+%D0%9C%D0%B0%D1%80%D1%82%D1%8B%D0%BD%D0%BE%D0%B2+10'
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function normalize_phone:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
filename:       /in/l6PpZ
function name:  normalize_phone
number of ops:  38
compiled vars:  !0 = $phone, !1 = $matches, !2 = $normalized_phone
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        INIT_FCALL                                               'preg_match'
          2        SEND_VAL                                                 '%2F%28%28%3F%3A%5Cd%2B%5B%5Cs%5C-%5C%28%5C%29%2B%5D%2B%29%7B5%2C%7D%29%2F'
          3        SEND_VAR                                                 !0
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
    5     6        INIT_FCALL                                               'preg_replace'
          7        SEND_VAL                                                 '%2F%5B%5E0-9%5D%2B%2F'
          8        SEND_VAL                                                 ''
          9        FETCH_DIM_R                                      ~4      !1, 1
         10        SEND_VAL                                                 ~4
         11        DO_ICALL                                         $5      
         12        ASSIGN                                                   !2, $5
    6    13        INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !2
         15        SEND_VAL                                                 0
         16        SEND_VAL                                                 1
         17        DO_ICALL                                         $7      
         18        IS_IDENTICAL                                             $7, '7'
         19      > JMPZ                                                     ~8, ->27
    7    20    >   INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !2
         22        SEND_VAL                                                 1
         23        DO_ICALL                                         $9      
         24        CONCAT                                           ~10     '8', $9
         25        ASSIGN                                                   !2, ~10
         26      > JMP                                                      ->36
    8    27    >   INIT_FCALL                                               'substr'
         28        SEND_VAR                                                 !2
         29        SEND_VAL                                                 0
         30        SEND_VAL                                                 1
         31        DO_ICALL                                         $12     
         32        IS_IDENTICAL                                             $12, '9'
         33      > JMPZ                                                     ~13, ->36
    9    34    >   CONCAT                                           ~14     '8', !2
         35        ASSIGN                                                   !2, ~14
   10    36    > > RETURN                                                   !2
   11    37*     > RETURN                                                   null

End of function normalize_phone

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.64 ms | 1403 KiB | 20 Q