3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitStreetNameNumber($str, $numRequired = false) { $str = trim($str); $tmp = @preg_split('/[0-9]+/', $str); print_r($tmp); if ( (0 >= strlen($str) || 0 >= strlen(trim($tmp[0]))) || ($numRequired && 0 >= strlen(trim(str_replace(trim($tmp[0]), '', $str)))) ) { return false; } return array( 'name' => trim($tmp[0]), 'num' => trim(str_replace(trim($tmp[0]), '', $str)), ); } $a = array( 'Karlstr. 2', '12345', 'Karl Straße 2d', 'Karlsplatz 14 a', '', 'Karlsplatz', ); foreach($a as $b) { $c = splitStreetNameNumber($b); if (!$c) { printf("Match result for '%s': Not a valid address.\r\n", $b); } else { printf("Match result for '%s': Streetname: '%s', Streetnumber: '%s'.\r\n", $b, $c['name'], $c['num']); } /* Prints: * Streetname: 'Karlstr.', Streetnumber: '2'. * Not a valid address. * Streetname: 'Karl Straße', Streetnumber: '2d'. * Streetname: 'Karlsplatz', Streetnumber: '14 a'. * Not a valid address. * Streetname: 'Karlsplatz', Streetnumber: ''. */ } foreach($a as $b) { $c = splitStreetNameNumber($b, true); if (!$c) { printf("Match result for '%s': Not a valid address.\r\n", $b); } else { printf("Match result for '%s': Streetname: '%s', Streetnumber: '%s'.\r\n", $b, $c['name'], $c['num']); } /* Prints: * Streetname: 'Karlstr.', Streetnumber: '2'. * Not a valid address. * Streetname: 'Karl Straße', Streetnumber: '2d'. * Streetname: 'Karlsplatz', Streetnumber: '14 a'. * Not a valid address. * Not a valid address. */ }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 23
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 23
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 47
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 47
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
Branch analysis from position: 23
filename:       /in/GD9Z1
function name:  (null)
number of ops:  49
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   29     1      > FE_RESET_R                                       $4      !0, ->23
          2    > > FE_FETCH_R                                               $4, !1, ->23
   30     3    >   INIT_FCALL                                               'splitstreetnamenumber'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   31     7        BOOL_NOT                                         ~7      !2
          8      > JMPZ                                                     ~7, ->14
   32     9    >   INIT_FCALL                                               'printf'
         10        SEND_VAL                                                 'Match+result+for+%27%25s%27%3A+Not+a+valid+address.%0D%0A'
         11        SEND_VAR                                                 !1
         12        DO_ICALL                                                 
         13      > JMP                                                      ->22
   35    14    >   INIT_FCALL                                               'printf'
         15        SEND_VAL                                                 'Match+result+for+%27%25s%27%3A+Streetname%3A+%27%25s%27%2C+Streetnumber%3A+%27%25s%27.%0D%0A'
         16        SEND_VAR                                                 !1
         17        FETCH_DIM_R                                      ~9      !2, 'name'
         18        SEND_VAL                                                 ~9
         19        FETCH_DIM_R                                      ~10     !2, 'num'
         20        SEND_VAL                                                 ~10
         21        DO_ICALL                                                 
   29    22    > > JMP                                                      ->2
         23    >   FE_FREE                                                  $4
   47    24      > FE_RESET_R                                       $12     !0, ->47
         25    > > FE_FETCH_R                                               $12, !1, ->47
   48    26    >   INIT_FCALL                                               'splitstreetnamenumber'
         27        SEND_VAR                                                 !1
         28        SEND_VAL                                                 <true>
         29        DO_FCALL                                      0  $13     
         30        ASSIGN                                                   !2, $13
   49    31        BOOL_NOT                                         ~15     !2
         32      > JMPZ                                                     ~15, ->38
   50    33    >   INIT_FCALL                                               'printf'
         34        SEND_VAL                                                 'Match+result+for+%27%25s%27%3A+Not+a+valid+address.%0D%0A'
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                                 
         37      > JMP                                                      ->46
   53    38    >   INIT_FCALL                                               'printf'
         39        SEND_VAL                                                 'Match+result+for+%27%25s%27%3A+Streetname%3A+%27%25s%27%2C+Streetnumber%3A+%27%25s%27.%0D%0A'
         40        SEND_VAR                                                 !1
         41        FETCH_DIM_R                                      ~17     !2, 'name'
         42        SEND_VAL                                                 ~17
         43        FETCH_DIM_R                                      ~18     !2, 'num'
         44        SEND_VAL                                                 ~18
         45        DO_ICALL                                                 
   47    46    > > JMP                                                      ->25
         47    >   FE_FREE                                                  $12
   63    48      > RETURN                                                   1

Function splitstreetnamenumber:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
2 jumps found. (Code = 47) Position 1 = 27, Position 2 = 44
Branch analysis from position: 27
2 jumps found. (Code = 46) Position 1 = 28, Position 2 = 43
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
Branch analysis from position: 44
Branch analysis from position: 26
filename:       /in/GD9Z1
function name:  splitStreetNameNumber
number of ops:  66
compiled vars:  !0 = $str, !1 = $numRequired, !2 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
    4     2        INIT_FCALL                                               'trim'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $3      
          5        ASSIGN                                                   !0, $3
    5     6        BEGIN_SILENCE                                    ~5      
          7        INIT_FCALL                                               'preg_split'
          8        SEND_VAL                                                 '%2F%5B0-9%5D%2B%2F'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $6      
         11        END_SILENCE                                              ~5
         12        ASSIGN                                                   !2, $6
    7    13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
    8    16        STRLEN                                           ~9      !0
         17        IS_SMALLER_OR_EQUAL                              ~10     ~9, 0
         18      > JMPNZ_EX                                         ~10     ~10, ->26
         19    >   INIT_FCALL                                               'trim'
         20        FETCH_DIM_R                                      ~11     !2, 0
         21        SEND_VAL                                                 ~11
         22        DO_ICALL                                         $12     
         23        STRLEN                                           ~13     $12
         24        IS_SMALLER_OR_EQUAL                              ~14     ~13, 0
         25        BOOL                                             ~10     ~14
         26    > > JMPNZ_EX                                         ~10     ~10, ->44
    9    27    > > JMPZ_EX                                          ~15     !1, ->43
         28    >   INIT_FCALL                                               'trim'
         29        INIT_FCALL                                               'str_replace'
         30        INIT_FCALL                                               'trim'
         31        FETCH_DIM_R                                      ~16     !2, 0
         32        SEND_VAL                                                 ~16
         33        DO_ICALL                                         $17     
         34        SEND_VAR                                                 $17
         35        SEND_VAL                                                 ''
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $18     
         38        SEND_VAR                                                 $18
         39        DO_ICALL                                         $19     
         40        STRLEN                                           ~20     $19
         41        IS_SMALLER_OR_EQUAL                              ~21     ~20, 0
         42        BOOL                                             ~15     ~21
         43    >   BOOL                                             ~10     ~15
         44    > > JMPZ                                                     ~10, ->46
   10    45    > > RETURN                                                   <false>
   14    46    >   INIT_FCALL                                               'trim'
         47        FETCH_DIM_R                                      ~22     !2, 0
         48        SEND_VAL                                                 ~22
         49        DO_ICALL                                         $23     
         50        INIT_ARRAY                                       ~24     $23, 'name'
   15    51        INIT_FCALL                                               'trim'
         52        INIT_FCALL                                               'str_replace'
         53        INIT_FCALL                                               'trim'
         54        FETCH_DIM_R                                      ~25     !2, 0
         55        SEND_VAL                                                 ~25
         56        DO_ICALL                                         $26     
         57        SEND_VAR                                                 $26
         58        SEND_VAL                                                 ''
         59        SEND_VAR                                                 !0
         60        DO_ICALL                                         $27     
         61        SEND_VAR                                                 $27
         62        DO_ICALL                                         $28     
         63        ADD_ARRAY_ELEMENT                                ~24     $28, 'num'
         64      > RETURN                                                   ~24
   17    65*     > RETURN                                                   null

End of function splitstreetnamenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
197.25 ms | 1411 KiB | 25 Q