3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test = ['07511 111111', '+447511 111111', '+44 (0) 7511 111111', '07211 111111', '3749853857', '0712121211233', '00447511 111111']; foreach ($test as $input) { //step 1 - reduce it to digits: preg_match_all('([\+]{0,1}[^\(\) ][0-9]+)', $input, $digits); $digits = implode($digits[0]); //now for step 2.. start by removing +44 and replacing it with 0 if (substr($digits, 0, 3) == '+44') { $digits = str_replace('+44', '0', $digits); } //by this point we should have just a UK-style number, but we must validate it: if ((substr($digits, 2, 1) > 3) && strlen($digits) == 11) { //valid UK mobile number! echo "\nValid UK mobile number $digits"; } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 41
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 41
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 26
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 33, Position 2 = 36
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 40
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 40
Branch analysis from position: 36
Branch analysis from position: 26
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/m03j1
function name:  (null)
number of ops:  43
compiled vars:  !0 = $test, !1 = $input, !2 = $digits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1      > FE_RESET_R                                       $4      !0, ->41
          2    > > FE_FETCH_R                                               $4, !1, ->41
    8     3    >   INIT_FCALL                                               'preg_match_all'
          4        SEND_VAL                                                 '%28%5B%5C%2B%5D%7B0%2C1%7D%5B%5E%5C%28%5C%29+%5D%5B0-9%5D%2B%29'
          5        SEND_VAR                                                 !1
          6        SEND_REF                                                 !2
          7        DO_ICALL                                                 
    9     8        INIT_FCALL                                               'implode'
          9        FETCH_DIM_R                                      ~6      !2, 0
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   12    13        INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !2
         15        SEND_VAL                                                 0
         16        SEND_VAL                                                 3
         17        DO_ICALL                                         $9      
         18        IS_EQUAL                                                 $9, '%2B44'
         19      > JMPZ                                                     ~10, ->26
   14    20    >   INIT_FCALL                                               'str_replace'
         21        SEND_VAL                                                 '%2B44'
         22        SEND_VAL                                                 '0'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $11     
         25        ASSIGN                                                   !2, $11
   18    26    >   INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !2
         28        SEND_VAL                                                 2
         29        SEND_VAL                                                 1
         30        DO_ICALL                                         $13     
         31        IS_SMALLER                                       ~14     3, $13
         32      > JMPZ_EX                                          ~14     ~14, ->36
         33    >   STRLEN                                           ~15     !2
         34        IS_EQUAL                                         ~16     ~15, 11
         35        BOOL                                             ~14     ~16
         36    > > JMPZ                                                     ~14, ->40
   21    37    >   NOP                                                      
         38        FAST_CONCAT                                      ~17     '%0AValid+UK+mobile+number+', !2
         39        ECHO                                                     ~17
    5    40    > > JMP                                                      ->2
         41    >   FE_FREE                                                  $4
   23    42      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.16 ms | 1400 KiB | 21 Q