3v4l.org

run code in 500+ 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 = 73
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 73
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 = 72
Branch analysis from position: 29
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 71
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 71
Branch analysis from position: 33
4 jumps found. (Code = 188) Position 1 = 43, Position 2 = 48, Position 3 = 64, Position 4 = 38
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
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 = 51, Position 2 = 59
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 70
Branch analysis from position: 70
Branch analysis from position: 64
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 = 64
Branch analysis from position: 64
Branch analysis from position: 48
Branch analysis from position: 43
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 71
Branch analysis from position: 72
Branch analysis from position: 23
Branch analysis from position: 73
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 73
filename:       /in/WWUdJ
function name:  (null)
number of ops:  75
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, ->73
          2    > > FE_FETCH_R                                                   $8, !1, ->73
   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, ->72
   20    29    >   ASSIGN                                                       !3, 0
   21    30        FETCH_DIM_R                                          ~21     !2, 'param'
         31      > FE_RESET_R                                           $22     ~21, ->71
         32    > > FE_FETCH_R                                                   $22, !4, ->71
   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, ], ->64
   25    38    >   IS_EQUAL                                                     !4, 'adress'
         39      > JMPNZ                                                        ~27, ->43
   28    40    >   IS_EQUAL                                                     !4, 'port'
         41      > JMPNZ                                                        ~27, ->48
         42    > > JMP                                                          ->64
   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                                                          ->70
   29    48    >   FRAMELESS_ICALL_2                preg_match          ~31     '%2F%5E%5Cd%7B3%7D%24%2F', !5
         49        ASSIGN                                               ~32     !6, ~31
         50      > JMPZ                                                         ~32, ->59
   30    51    >   INIT_FCALL                                                   'var_dump'
         52        SEND_VAR                                                     !6
         53        DO_ICALL                                                     
   31    54        ROPE_INIT                                         3  ~35     'PORT+IS+'
         55        ROPE_ADD                                          1  ~35     ~35, !5
         56        ROPE_END                                          2  ~34     ~35, '%0A'
         57        ECHO                                                         ~34
   29    58      > JMP                                                          ->63
   33    59    >   ROPE_INIT                                         3  ~38     'PORT+MUST+HAVE+EXACTLY+3+DIGITS+-+Got%3A+'
         60        ROPE_ADD                                          1  ~38     ~38, !5
         61        ROPE_END                                          2  ~37     ~38, '%0A'
         62        ECHO                                                         ~37
   35    63    > > JMP                                                          ->70
   37    64    >   ROPE_INIT                                         5  ~41     'UNKNOWN+PARAMETER+'
         65        ROPE_ADD                                          1  ~41     ~41, !4
         66        ROPE_ADD                                          2  ~41     ~41, '%3D'
         67        ROPE_ADD                                          3  ~41     ~41, !5
         68        ROPE_END                                          4  ~40     ~41, '%0A'
         69        ECHO                                                         ~40
   21    70    > > JMP                                                          ->32
         71    >   FE_FREE                                                      $22
    9    72    > > JMP                                                          ->2
         73    >   FE_FREE                                                      $8
   41    74      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
160.01 ms | 2206 KiB | 16 Q