3v4l.org

run code in 300+ PHP versions simultaneously
<?php function splitStreetNameNumber($str) { $str = trim($str); $tmp = @preg_split('/[0-9]+/', $str); if (0 >= strlen($str) || 0 >= strlen(trim($tmp[0]))) { 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/T4H0l
function name:  (null)
number of ops:  21
compiled vars:  !0 = $a, !1 = $b, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   26     1      > FE_RESET_R                                       $4      !0, ->19
          2    > > FE_FETCH_R                                               $4, !1, ->19
   27     3    >   INIT_FCALL                                               'splitstreetnamenumber'
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $5      
          6        ASSIGN                                                   !2, $5
   28     7        BOOL_NOT                                         ~7      !2
          8      > JMPZ                                                     ~7, ->11
   29     9    >   ECHO                                                     'Not+a+valid+address.%0D%0A'
         10      > JMP                                                      ->18
   32    11    >   INIT_FCALL                                               'printf'
         12        SEND_VAL                                                 'Streetname%3A+%25s%2C+Streetnumber%3A+%25s.%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                                                 
   26    18    > > JMP                                                      ->2
         19    >   FE_FREE                                                  $4
   34    20      > RETURN                                                   1

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

End of function splitstreetnamenumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.16 ms | 1403 KiB | 22 Q