3v4l.org

run code in 300+ PHP versions simultaneously
<?php $test1 = '07511 111111'; $test2 = '+447511 111111'; $test3 = '+44 (0) 7511 111111'; //step 1 - reduce it to digits: preg_match_all('([\+]{0,1}[^\(\) ][0-9]+)', $test1, $digits); $digits = implode($digits[0]); var_dump($digits); //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, 3, 1) > 3) && strlen($digits) == 11) { //valid UK mobile number! echo "valid UK mobile number $digits"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 29
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 36, Position 2 = 39
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 43
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 39
Branch analysis from position: 29
filename:       /in/PiPQG
function name:  (null)
number of ops:  44
compiled vars:  !0 = $test1, !1 = $test2, !2 = $test3, !3 = $digits
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '07511+111111'
    4     1        ASSIGN                                                   !1, '%2B447511+111111'
    5     2        ASSIGN                                                   !2, '%2B44+%280%29+7511+111111'
    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                                                 !0
          6        SEND_REF                                                 !3
          7        DO_ICALL                                                 
    9     8        INIT_FCALL                                               'implode'
          9        FETCH_DIM_R                                      ~8      !3, 0
         10        SEND_VAL                                                 ~8
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !3, $9
   10    13        INIT_FCALL                                               'var_dump'
         14        SEND_VAR                                                 !3
         15        DO_ICALL                                                 
   12    16        INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !3
         18        SEND_VAL                                                 0
         19        SEND_VAL                                                 3
         20        DO_ICALL                                         $12     
         21        IS_EQUAL                                                 $12, '%2B44'
         22      > JMPZ                                                     ~13, ->29
   14    23    >   INIT_FCALL                                               'str_replace'
         24        SEND_VAL                                                 '%2B44'
         25        SEND_VAL                                                 '0'
         26        SEND_VAR                                                 !3
         27        DO_ICALL                                         $14     
         28        ASSIGN                                                   !3, $14
   18    29    >   INIT_FCALL                                               'substr'
         30        SEND_VAR                                                 !3
         31        SEND_VAL                                                 3
         32        SEND_VAL                                                 1
         33        DO_ICALL                                         $16     
         34        IS_SMALLER                                       ~17     3, $16
         35      > JMPZ_EX                                          ~17     ~17, ->39
         36    >   STRLEN                                           ~18     !3
         37        IS_EQUAL                                         ~19     ~18, 11
         38        BOOL                                             ~17     ~19
         39    > > JMPZ                                                     ~17, ->43
   21    40    >   NOP                                                      
         41        FAST_CONCAT                                      ~20     'valid+UK+mobile+number+', !3
         42        ECHO                                                     ~20
   22    43    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.17 ms | 1400 KiB | 23 Q