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 && 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) { echo "Not a valid address.\r\n"; } else { printf("Streetname: '%s', Streetnumber: '%s'.\r\n", $c['name'], $c['num']); } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 19
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/NmYXh
function name:  (null)
number of ops:  21
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                   !0, <array>
   27     1      > FE_RESET_R                                       $4      !0, ->19
          2    > > FE_FETCH_R                                               $4, !1, ->19
   28     3    >   INIT_FCALL                                               'splitstreetnamenumber'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   29     7        BOOL_NOT                                         ~7      !2
          8      > JMPZ                                                     ~7, ->11
   30     9    >   ECHO                                                     'Not+a+valid+address.%0D%0A'
         10      > JMP                                                      ->18
   33    11    >   INIT_FCALL                                               'printf'
         12        SEND_VAL                                                 'Streetname%3A+%27%25s%27%2C+Streetnumber%3A+%27%25s%27.%0D%0A'
         13        FETCH_DIM_R                                      ~8      !2, 'name'
         14        SEND_VAL                                                 ~8
         15        FETCH_DIM_R                                      ~9      !2, 'num'
         16        SEND_VAL                                                 ~9
         17        DO_ICALL                                                 
   27    18    > > JMP                                                      ->2
         19    >   FE_FREE                                                  $4
   35    20      > 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 = 33
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 35
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 33
Branch analysis from position: 23
filename:       /in/NmYXh
function name:  splitStreetNameNumber
number of ops:  55
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, ->33
    8    24    > > JMPZ_EX                                          ~14     !1, ->32
         25    >   INIT_FCALL                                               'trim'
         26        FETCH_DIM_R                                      ~15     !2, 1
         27        SEND_VAL                                                 ~15
         28        DO_ICALL                                         $16     
         29        STRLEN                                           ~17     $16
         30        IS_SMALLER_OR_EQUAL                              ~18     ~17, 0
         31        BOOL                                             ~14     ~18
         32    >   BOOL                                             ~9      ~14
         33    > > JMPZ                                                     ~9, ->35
    9    34    > > RETURN                                                   <false>
   13    35    >   INIT_FCALL                                               'trim'
         36        FETCH_DIM_R                                      ~19     !2, 0
         37        SEND_VAL                                                 ~19
         38        DO_ICALL                                         $20     
         39        INIT_ARRAY                                       ~21     $20, 'name'
   14    40        INIT_FCALL                                               'trim'
         41        INIT_FCALL                                               'str_replace'
         42        INIT_FCALL                                               'trim'
         43        FETCH_DIM_R                                      ~22     !2, 0
         44        SEND_VAL                                                 ~22
         45        DO_ICALL                                         $23     
         46        SEND_VAR                                                 $23
         47        SEND_VAL                                                 ''
         48        SEND_VAR                                                 !0
         49        DO_ICALL                                         $24     
         50        SEND_VAR                                                 $24
         51        DO_ICALL                                         $25     
         52        ADD_ARRAY_ELEMENT                                ~21     $25, 'num'
         53      > RETURN                                                   ~21
   16    54*     > RETURN                                                   null

End of function splitstreetnamenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.28 ms | 1407 KiB | 22 Q