3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitStreetNameNumber($str, $numRequired = false) { $str = trim($str); $tmp = @preg_split('/[0-9]+/', $str); if ( (0 >= strlen($str) || 0 >= strlen(trim($tmp[0]))) || ($numRequired && (!isset($tmp[1]) || (isset($tmp[1]) && 0 >= strlen(trim($tmp[1]))))) ) { 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/QBnPT
function name:  (null)
number of ops:  49
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
   46    24      > FE_RESET_R                                       $12     !0, ->47
         25    > > FE_FETCH_R                                               $12, !1, ->47
   47    26    >   INIT_FCALL                                               'splitstreetnamenumber'
         27        SEND_VAR                                                 !1
         28        SEND_VAL                                                 <true>
         29        DO_FCALL                                      0  $13     
         30        ASSIGN                                                   !2, $13
   48    31        BOOL_NOT                                         ~15     !2
         32      > JMPZ                                                     ~15, ->38
   49    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
   52    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                                                 
   46    46    > > JMP                                                      ->25
         47    >   FE_FREE                                                  $12
   62    48      > RETURN                                                   1

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

End of function splitstreetnamenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.66 ms | 1410 KiB | 23 Q