3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getStringBetween($str,$from,$to){ if (preg_match("/$from([^$from]+)$to/", $str, $matches)) return $matches[1]; else return ''; } $str = 'SIM UMTS ITALIA 35GB BLACK'; echo getStringBetween($str, ' ', 'GB') . "\n"; $str2 = 'SIM UMTS ITALIA IPHONE 2 MEGAPIXEL'; echo getStringBetween($str2, ' ', 'GB') . "\n"; $str3 = 'SIM UMTS ITALIA 15.5" BLACK'; echo getStringBetween($str3, ' ', '"') . "\n";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/76AbI
function name:  (null)
number of ops:  25
compiled vars:  !0 = $str, !1 = $str2, !2 = $str3
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   ASSIGN                                                   !0, 'SIM+UMTS+ITALIA+35GB+BLACK'
   11     1        INIT_FCALL                                               'getstringbetween'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '+'
          4        SEND_VAL                                                 'GB'
          5        DO_FCALL                                      0  $4      
          6        CONCAT                                           ~5      $4, '%0A'
          7        ECHO                                                     ~5
   13     8        ASSIGN                                                   !1, 'SIM+UMTS+ITALIA+IPHONE+2+MEGAPIXEL'
   14     9        INIT_FCALL                                               'getstringbetween'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 '+'
         12        SEND_VAL                                                 'GB'
         13        DO_FCALL                                      0  $7      
         14        CONCAT                                           ~8      $7, '%0A'
         15        ECHO                                                     ~8
   16    16        ASSIGN                                                   !2, 'SIM+UMTS+ITALIA+15.5%22+BLACK'
   17    17        INIT_FCALL                                               'getstringbetween'
         18        SEND_VAR                                                 !2
         19        SEND_VAL                                                 '+'
         20        SEND_VAL                                                 '%22'
         21        DO_FCALL                                      0  $10     
         22        CONCAT                                           ~11     $10, '%0A'
         23        ECHO                                                     ~11
         24      > RETURN                                                   1

Function getstringbetween:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/76AbI
function name:  getStringBetween
number of ops:  21
compiled vars:  !0 = $str, !1 = $from, !2 = $to, !3 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    4     3        INIT_FCALL                                               'preg_match'
          4        ROPE_INIT                                     7  ~5      '%2F'
          5        ROPE_ADD                                      1  ~5      ~5, !1
          6        ROPE_ADD                                      2  ~5      ~5, '%28%5B%5E'
          7        ROPE_ADD                                      3  ~5      ~5, !1
          8        ROPE_ADD                                      4  ~5      ~5, '%5D%2B%29'
          9        ROPE_ADD                                      5  ~5      ~5, !2
         10        ROPE_END                                      6  ~4      ~5, '%2F'
         11        SEND_VAL                                                 ~4
         12        SEND_VAR                                                 !0
         13        SEND_REF                                                 !3
         14        DO_ICALL                                         $9      
         15      > JMPZ                                                     $9, ->19
    5    16    >   FETCH_DIM_R                                      ~10     !3, 1
         17      > RETURN                                                   ~10
         18*       JMP                                                      ->20
    7    19    > > RETURN                                                   ''
    8    20*     > RETURN                                                   null

End of function getstringbetween

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.14 ms | 1407 KiB | 18 Q