3v4l.org

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.82 ms | 1412 KiB | 23 Q