3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** Some strings to test our code */ $testStrings=[ "adress=example.com port=464", "adress =example.com\nport=4645", "port=1 protocol=https adress= example.com", ]; /** Test for each string */ foreach($testStrings as $string) { print "\n\nTESTING:'".escapeshellarg($string)."'\n"; /** First method - does not match them all */ if(preg_match('/\badress=([a-z\.]*)\s+port=(\d*)/',$string,$matches)) { print "Matched {$matches[1]}:{$matches[2]}\n"; } /** Second method - get param/value pairs first, then check them */ if(preg_match_all('/\b(?P<param>[^\d\s]\S*)\s*=\s*(?P<value>\S*)(?:\s|$)/m',$string,$matches)) { //var_dump($matches); // Uncomment to see the raw data. $i=0; // We need an index. foreach($matches['param'] as $param) { $value=$matches['value'][$i]; // Put value in local $value $i++; switch($param) { // Find parameters we know, complain if needed. case "adress": print "ADDRESS IS $value\n"; break; case "port": if(($result=preg_match('/^\d{3}$/',$value))) { var_dump($result); print "PORT IS $value\n"; } else { print "PORT MUST HAVE EXACTLY 3 DIGITS - Got: $value\n"; } break; default: print "UNKNOWN PARAMETER $param=$value\n"; } } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 76
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 76
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 75
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 74
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 74
Branch analysis from position: 33
4 jumps found. (Code = 188) Position 1 = 43, Position 2 = 48, Position 3 = 67, Position 4 = 38
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 62
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 66
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 43
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 48
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
Branch analysis from position: 48
Branch analysis from position: 43
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 74
Branch analysis from position: 75
Branch analysis from position: 23
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 76
filename:       /in/WWUdJ
function name:  (null)
number of ops:  78
compiled vars:  !0 = $testStrings, !1 = $string, !2 = $matches, !3 = $i, !4 = $param, !5 = $value, !6 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1      > FE_RESET_R                                       $8      !0, ->76
          2    > > FE_FETCH_R                                               $8, !1, ->76
   10     3    >   INIT_FCALL                                               'escapeshellarg'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $9      
          6        CONCAT                                           ~10     '%0A%0ATESTING%3A%27', $9
          7        CONCAT                                           ~11     ~10, '%27%0A'
          8        ECHO                                                     ~11
   13     9        INIT_FCALL                                               'preg_match'
         10        SEND_VAL                                                 '%2F%5Cbadress%3D%28%5Ba-z%5C.%5D%2A%29%5Cs%2Bport%3D%28%5Cd%2A%29%2F'
         11        SEND_VAR                                                 !1
         12        SEND_REF                                                 !2
         13        DO_ICALL                                         $12     
         14      > JMPZ                                                     $12, ->23
   14    15    >   ROPE_INIT                                     5  ~16     'Matched+'
         16        FETCH_DIM_R                                      ~13     !2, 1
         17        ROPE_ADD                                      1  ~16     ~16, ~13
         18        ROPE_ADD                                      2  ~16     ~16, '%3A'
         19        FETCH_DIM_R                                      ~14     !2, 2
         20        ROPE_ADD                                      3  ~16     ~16, ~14
         21        ROPE_END                                      4  ~15     ~16, '%0A'
         22        ECHO                                                     ~15
   18    23    >   INIT_FCALL                                               'preg_match_all'
         24        SEND_VAL                                                 '%2F%5Cb%28%3FP%3Cparam%3E%5B%5E%5Cd%5Cs%5D%5CS%2A%29%5Cs%2A%3D%5Cs%2A%28%3FP%3Cvalue%3E%5CS%2A%29%28%3F%3A%5Cs%7C%24%29%2Fm'
         25        SEND_VAR                                                 !1
         26        SEND_REF                                                 !2
         27        DO_ICALL                                         $19     
         28      > JMPZ                                                     $19, ->75
   20    29    >   ASSIGN                                                   !3, 0
   21    30        FETCH_DIM_R                                      ~21     !2, 'param'
         31      > FE_RESET_R                                       $22     ~21, ->74
         32    > > FE_FETCH_R                                               $22, !4, ->74
   22    33    >   FETCH_DIM_R                                      ~23     !2, 'value'
         34        FETCH_DIM_R                                      ~24     ~23, !3
         35        ASSIGN                                                   !5, ~24
   23    36        PRE_INC                                                  !3
   24    37      > SWITCH_STRING                                            !4, [ 'adress':->43, 'port':->48, ], ->67
   25    38    >   IS_EQUAL                                                 !4, 'adress'
         39      > JMPNZ                                                    ~27, ->43
   28    40    >   IS_EQUAL                                                 !4, 'port'
         41      > JMPNZ                                                    ~27, ->48
         42    > > JMP                                                      ->67
   26    43    >   ROPE_INIT                                     3  ~29     'ADDRESS+IS+'
         44        ROPE_ADD                                      1  ~29     ~29, !5
         45        ROPE_END                                      2  ~28     ~29, '%0A'
         46        ECHO                                                     ~28
   27    47      > JMP                                                      ->73
   29    48    >   INIT_FCALL                                               'preg_match'
         49        SEND_VAL                                                 '%2F%5E%5Cd%7B3%7D%24%2F'
         50        SEND_VAR                                                 !5
         51        DO_ICALL                                         $31     
         52        ASSIGN                                           ~32     !6, $31
         53      > JMPZ                                                     ~32, ->62
   30    54    >   INIT_FCALL                                               'var_dump'
         55        SEND_VAR                                                 !6
         56        DO_ICALL                                                 
   31    57        ROPE_INIT                                     3  ~35     'PORT+IS+'
         58        ROPE_ADD                                      1  ~35     ~35, !5
         59        ROPE_END                                      2  ~34     ~35, '%0A'
         60        ECHO                                                     ~34
   29    61      > JMP                                                      ->66
   33    62    >   ROPE_INIT                                     3  ~38     'PORT+MUST+HAVE+EXACTLY+3+DIGITS+-+Got%3A+'
         63        ROPE_ADD                                      1  ~38     ~38, !5
         64        ROPE_END                                      2  ~37     ~38, '%0A'
         65        ECHO                                                     ~37
   35    66    > > JMP                                                      ->73
   37    67    >   ROPE_INIT                                     5  ~41     'UNKNOWN+PARAMETER+'
         68        ROPE_ADD                                      1  ~41     ~41, !4
         69        ROPE_ADD                                      2  ~41     ~41, '%3D'
         70        ROPE_ADD                                      3  ~41     ~41, !5
         71        ROPE_END                                      4  ~40     ~41, '%0A'
         72        ECHO                                                     ~40
   21    73    > > JMP                                                      ->32
         74    >   FE_FREE                                                  $22
    9    75    > > JMP                                                      ->2
         76    >   FE_FREE                                                  $8
   41    77      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.44 ms | 1022 KiB | 17 Q