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

End of function splitstreetnamenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.49 ms | 1411 KiB | 25 Q