3v4l.org

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

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

End of function splitstreetnamenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.64 ms | 1411 KiB | 23 Q