3v4l.org

run code in 300+ PHP versions simultaneously
<?php $emailAddr = "test@test.com"; $isDebug = true; // logic stolen shamelessly from an article in linuxjournal.com www.linuxjournal.com/article/9585 // return true if valid, false if not // set the error code to indicate the problem if not // 5 - no '@' found // 10 - email address name is longer than 64 // 15 - email domain name is longer than 64 // 20 - email address name begins or ends with a '.' // 25 - email address name has two consecutive dots '..' // 30 - invalid character in domain // 35 - domain has two consecutive dots '..' // 40 - invalid character in address name // 45 - domain not found in DNS $errorCode = 0; $isValid = true; $atIndex = strrpos($emailAddr, "@"); if (is_bool($atIndex) && !$atIndex) { if ($isDebug) print $emailAddr . "no '@' found<br>"; $errorCode = 5; $isValid = false; } else { $domain = substr($emailAddr, $atIndex+1); $local = substr($emailAddr, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { if ($isDebug) print $emailAddr . " -local part length exceeded<br>"; $errorCode = 10; $isValid = false; } else if ($domainLen < 1 || $domainLen > 255) { if ($isDebug) print $emailAddr . " -domain part length exceeded<br>"; $errorCode = 15; $isValid = false; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { if ($isDebug) print $emailAddr . " -local part starts or ends with '.'<br>"; $errorCode = 20; $isValid = false; } else if (preg_match('/\\.\\./', $local)) { if ($isDebug) print $emailAddr . " -local part has two consecutive dots<br>"; $errorCode = 25; $isValid = false; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { if ($isDebug) print $emailAddr . " -character not valid in domain part<br>"; $errorCode = 30; $isValid = false; } else if (preg_match('/\\.\\./', $domain)) { if ($isDebug) print $emailAddr . " -domain part has two consecutive dots<br>"; $errorCode = 35; $isValid = false; } else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { if ($isDebug) print $emailAddr . " -character not valid in local part unless local part is quoted<br>"; if (!preg_match('/^"(\\\\"|[^"])+"$/',str_replace("\\\\","",$local))) { $errorCode = 40; $isValid = false; } } if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))){ if ($isDebug) { print $emailAddr . " -domain not found in DNS<br>"; $errorCode = 45; $isValid = false; } } } print $isValid; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 152
Branch analysis from position: 152
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 20
2 jumps found. (Code = 47) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 47
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 44
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
2 jumps found. (Code = 46) Position 1 = 134, Position 2 = 146
Branch analysis from position: 134
2 jumps found. (Code = 47) Position 1 = 139, Position 2 = 144
Branch analysis from position: 139
2 jumps found. (Code = 43) Position 1 = 147, Position 2 = 152
Branch analysis from position: 147
2 jumps found. (Code = 43) Position 1 = 148, Position 2 = 152
Branch analysis from position: 148
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 152
Branch analysis from position: 152
Branch analysis from position: 144
Branch analysis from position: 146
Branch analysis from position: 44
Branch analysis from position: 47
2 jumps found. (Code = 47) Position 1 = 49, Position 2 = 51
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 58
Branch analysis from position: 52
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 55
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
Branch analysis from position: 55
Branch analysis from position: 58
2 jumps found. (Code = 47) Position 1 = 61, Position 2 = 65
Branch analysis from position: 61
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 72
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 69
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
Branch analysis from position: 69
Branch analysis from position: 72
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 83
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 80
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
Branch analysis from position: 80
Branch analysis from position: 83
2 jumps found. (Code = 43) Position 1 = 89, Position 2 = 95
Branch analysis from position: 89
2 jumps found. (Code = 43) Position 1 = 90, Position 2 = 92
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
Branch analysis from position: 92
Branch analysis from position: 95
2 jumps found. (Code = 43) Position 1 = 100, Position 2 = 106
Branch analysis from position: 100
2 jumps found. (Code = 43) Position 1 = 101, Position 2 = 103
Branch analysis from position: 101
1 jumps found. (Code = 42) Position 1 = 133
Branch analysis from position: 133
Branch analysis from position: 103
Branch analysis from position: 106
2 jumps found. (Code = 43) Position 1 = 117, Position 2 = 133
Branch analysis from position: 117
2 jumps found. (Code = 43) Position 1 = 118, Position 2 = 120
Branch analysis from position: 118
2 jumps found. (Code = 43) Position 1 = 131, Position 2 = 133
Branch analysis from position: 131
2 jumps found. (Code = 46) Position 1 = 134, Position 2 = 146
Branch analysis from position: 134
Branch analysis from position: 146
Branch analysis from position: 133
Branch analysis from position: 120
Branch analysis from position: 133
Branch analysis from position: 65
Branch analysis from position: 51
Branch analysis from position: 40
Branch analysis from position: 13
filename:       /in/VOt28
function name:  (null)
number of ops:  154
compiled vars:  !0 = $emailAddr, !1 = $isDebug, !2 = $errorCode, !3 = $isValid, !4 = $atIndex, !5 = $domain, !6 = $local, !7 = $localLen, !8 = $domainLen
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'test%40test.com'
    3     1        ASSIGN                                                   !1, <true>
   16     2        ASSIGN                                                   !2, 0
   17     3        ASSIGN                                                   !3, <true>
   18     4        INIT_FCALL                                               'strrpos'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 '%40'
          7        DO_ICALL                                         $13     
          8        ASSIGN                                                   !4, $13
   20     9        TYPE_CHECK                                   12  ~15     !4
         10      > JMPZ_EX                                          ~15     ~15, ->13
         11    >   BOOL_NOT                                         ~16     !4
         12        BOOL                                             ~15     ~16
         13    > > JMPZ                                                     ~15, ->20
   21    14    > > JMPZ                                                     !1, ->17
   22    15    >   CONCAT                                           ~17     !0, 'no+%27%40%27+found%3Cbr%3E'
         16        ECHO                                                     ~17
   24    17    >   ASSIGN                                                   !2, 5
   25    18        ASSIGN                                                   !3, <false>
         19      > JMP                                                      ->152
   27    20    >   INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !0
         22        ADD                                              ~20     !4, 1
         23        SEND_VAL                                                 ~20
         24        DO_ICALL                                         $21     
         25        ASSIGN                                                   !5, $21
   28    26        INIT_FCALL                                               'substr'
         27        SEND_VAR                                                 !0
         28        SEND_VAL                                                 0
         29        SEND_VAR                                                 !4
         30        DO_ICALL                                         $23     
         31        ASSIGN                                                   !6, $23
   29    32        STRLEN                                           ~25     !6
         33        ASSIGN                                                   !7, ~25
   30    34        STRLEN                                           ~27     !5
         35        ASSIGN                                                   !8, ~27
   32    36        IS_SMALLER                                       ~29     !7, 1
         37      > JMPNZ_EX                                         ~29     ~29, ->40
         38    >   IS_SMALLER                                       ~30     64, !7
         39        BOOL                                             ~29     ~30
         40    > > JMPZ                                                     ~29, ->47
   33    41    > > JMPZ                                                     !1, ->44
   34    42    >   CONCAT                                           ~31     !0, '+-local+part+length+exceeded%3Cbr%3E'
         43        ECHO                                                     ~31
   36    44    >   ASSIGN                                                   !2, 10
   37    45        ASSIGN                                                   !3, <false>
         46      > JMP                                                      ->133
   38    47    >   IS_SMALLER                                       ~34     !8, 1
         48      > JMPNZ_EX                                         ~34     ~34, ->51
         49    >   IS_SMALLER                                       ~35     255, !8
         50        BOOL                                             ~34     ~35
         51    > > JMPZ                                                     ~34, ->58
   39    52    > > JMPZ                                                     !1, ->55
   40    53    >   CONCAT                                           ~36     !0, '+-domain+part+length+exceeded%3Cbr%3E'
         54        ECHO                                                     ~36
   42    55    >   ASSIGN                                                   !2, 15
   43    56        ASSIGN                                                   !3, <false>
         57      > JMP                                                      ->133
   44    58    >   FETCH_DIM_R                                      ~39     !6, 0
         59        IS_EQUAL                                         ~40     ~39, '.'
         60      > JMPNZ_EX                                         ~40     ~40, ->65
         61    >   SUB                                              ~41     !7, 1
         62        FETCH_DIM_R                                      ~42     !6, ~41
         63        IS_EQUAL                                         ~43     ~42, '.'
         64        BOOL                                             ~40     ~43
         65    > > JMPZ                                                     ~40, ->72
   45    66    > > JMPZ                                                     !1, ->69
   46    67    >   CONCAT                                           ~44     !0, '+-local+part+starts+or+ends+with+%27.%27%3Cbr%3E'
         68        ECHO                                                     ~44
   48    69    >   ASSIGN                                                   !2, 20
   49    70        ASSIGN                                                   !3, <false>
         71      > JMP                                                      ->133
   50    72    >   INIT_FCALL                                               'preg_match'
         73        SEND_VAL                                                 '%2F%5C.%5C.%2F'
         74        SEND_VAR                                                 !6
         75        DO_ICALL                                         $47     
         76      > JMPZ                                                     $47, ->83
   51    77    > > JMPZ                                                     !1, ->80
   52    78    >   CONCAT                                           ~48     !0, '+-local+part+has+two+consecutive+dots%3Cbr%3E'
         79        ECHO                                                     ~48
   54    80    >   ASSIGN                                                   !2, 25
   55    81        ASSIGN                                                   !3, <false>
         82      > JMP                                                      ->133
   56    83    >   INIT_FCALL                                               'preg_match'
         84        SEND_VAL                                                 '%2F%5E%5BA-Za-z0-9%5C-%5C.%5D%2B%24%2F'
         85        SEND_VAR                                                 !5
         86        DO_ICALL                                         $51     
         87        BOOL_NOT                                         ~52     $51
         88      > JMPZ                                                     ~52, ->95
   57    89    > > JMPZ                                                     !1, ->92
   58    90    >   CONCAT                                           ~53     !0, '+-character+not+valid+in+domain+part%3Cbr%3E'
         91        ECHO                                                     ~53
   60    92    >   ASSIGN                                                   !2, 30
   61    93        ASSIGN                                                   !3, <false>
         94      > JMP                                                      ->133
   62    95    >   INIT_FCALL                                               'preg_match'
         96        SEND_VAL                                                 '%2F%5C.%5C.%2F'
         97        SEND_VAR                                                 !5
         98        DO_ICALL                                         $56     
         99      > JMPZ                                                     $56, ->106
   63   100    > > JMPZ                                                     !1, ->103
   64   101    >   CONCAT                                           ~57     !0, '+-domain+part+has+two+consecutive+dots%3Cbr%3E'
        102        ECHO                                                     ~57
   66   103    >   ASSIGN                                                   !2, 35
   67   104        ASSIGN                                                   !3, <false>
        105      > JMP                                                      ->133
   68   106    >   INIT_FCALL                                               'preg_match'
        107        SEND_VAL                                                 '%2F%5E%28%5C%5C.%7C%5BA-Za-z0-9%21%23%25%26%60_%3D%5C%2F%24%27%2A%2B%3F%5E%7B%7D%7C%7E.-%5D%29%2B%24%2F'
        108        INIT_FCALL                                               'str_replace'
        109        SEND_VAL                                                 '%5C%5C'
        110        SEND_VAL                                                 ''
        111        SEND_VAR                                                 !6
        112        DO_ICALL                                         $60     
        113        SEND_VAR                                                 $60
        114        DO_ICALL                                         $61     
        115        BOOL_NOT                                         ~62     $61
        116      > JMPZ                                                     ~62, ->133
   69   117    > > JMPZ                                                     !1, ->120
   70   118    >   CONCAT                                           ~63     !0, '+-character+not+valid+in+local+part+unless+local+part+is+quoted%3Cbr%3E'
        119        ECHO                                                     ~63
   72   120    >   INIT_FCALL                                               'preg_match'
        121        SEND_VAL                                                 '%2F%5E%22%28%5C%5C%22%7C%5B%5E%22%5D%29%2B%22%24%2F'
        122        INIT_FCALL                                               'str_replace'
        123        SEND_VAL                                                 '%5C%5C'
        124        SEND_VAL                                                 ''
        125        SEND_VAR                                                 !6
        126        DO_ICALL                                         $64     
        127        SEND_VAR                                                 $64
        128        DO_ICALL                                         $65     
        129        BOOL_NOT                                         ~66     $65
        130      > JMPZ                                                     ~66, ->133
   73   131    >   ASSIGN                                                   !2, 40
   74   132        ASSIGN                                                   !3, <false>
   77   133    > > JMPZ_EX                                          ~69     !3, ->146
        134    >   INIT_FCALL                                               'checkdnsrr'
        135        SEND_VAR                                                 !5
        136        SEND_VAL                                                 'MX'
        137        DO_ICALL                                         $70     
        138      > JMPNZ_EX                                         ~71     $70, ->144
        139    >   INIT_FCALL                                               'checkdnsrr'
        140        SEND_VAR                                                 !5
        141        SEND_VAL                                                 'A'
        142        DO_ICALL                                         $72     
        143        BOOL                                             ~71     $72
        144    >   BOOL_NOT                                         ~73     ~71
        145        BOOL                                             ~69     ~73
        146    > > JMPZ                                                     ~69, ->152
   78   147    > > JMPZ                                                     !1, ->152
   79   148    >   CONCAT                                           ~74     !0, '+-domain+not+found+in+DNS%3Cbr%3E'
        149        ECHO                                                     ~74
   81   150        ASSIGN                                                   !2, 45
   82   151        ASSIGN                                                   !3, <false>
   86   152    >   ECHO                                                     !3
   87   153      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.2 ms | 1412 KiB | 23 Q