3v4l.org

run code in 300+ PHP versions simultaneously
<?php function extract_unit($string, $start, $end) { $pos = stripos($string, $start); $str = substr($string, $pos); $str_two = substr($str, strlen($start)); $second_pos = stripos($str_two, $end); $str_three = substr($str_two, 0, $second_pos); $unit = trim($str_three); // remove whitespaces return $unit; } $str = "X_HD01_1"; $str = "X_HD01_1, X_HD0003_2, X_HD12/12/2016/1_01"; $str_array =explode(',',$str); foreach($str_array as $val) { $unit = extract_unit($val, '_', '_'); // Outputs: acronym echo $unit."\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/e6DjZ
function name:  (null)
number of ops:  20
compiled vars:  !0 = $str, !1 = $str_array, !2 = $val, !3 = $unit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, 'X_HD01_1'
   23     1        ASSIGN                                                   !0, 'X_HD01_1%2C+X_HD0003_2%2C+X_HD12%2F12%2F2016%2F1_01'
   25     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%2C'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !1, $6
   27     7      > FE_RESET_R                                       $8      !1, ->18
          8    > > FE_FETCH_R                                               $8, !2, ->18
   29     9    >   INIT_FCALL                                               'extract_unit'
         10        SEND_VAR                                                 !2
         11        SEND_VAL                                                 '_'
         12        SEND_VAL                                                 '_'
         13        DO_FCALL                                      0  $9      
         14        ASSIGN                                                   !3, $9
   32    15        CONCAT                                           ~11     !3, '%0A'
         16        ECHO                                                     ~11
   27    17      > JMP                                                      ->8
         18    >   FE_FREE                                                  $8
   33    19      > RETURN                                                   1

Function extract_unit:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e6DjZ
function name:  extract_unit
number of ops:  36
compiled vars:  !0 = $string, !1 = $start, !2 = $end, !3 = $pos, !4 = $str, !5 = $str_two, !6 = $second_pos, !7 = $str_three, !8 = $unit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    6     3        INIT_FCALL                                               'stripos'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $9      
          7        ASSIGN                                                   !3, $9
    8     8        INIT_FCALL                                               'substr'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !3
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !4, $11
   10    13        INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !4
         15        STRLEN                                           ~13     !1
         16        SEND_VAL                                                 ~13
         17        DO_ICALL                                         $14     
         18        ASSIGN                                                   !5, $14
   12    19        INIT_FCALL                                               'stripos'
         20        SEND_VAR                                                 !5
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $16     
         23        ASSIGN                                                   !6, $16
   14    24        INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !5
         26        SEND_VAL                                                 0
         27        SEND_VAR                                                 !6
         28        DO_ICALL                                         $18     
         29        ASSIGN                                                   !7, $18
   16    30        INIT_FCALL                                               'trim'
         31        SEND_VAR                                                 !7
         32        DO_ICALL                                         $20     
         33        ASSIGN                                                   !8, $20
   18    34      > RETURN                                                   !8
   19    35*     > RETURN                                                   null

End of function extract_unit

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
266.47 ms | 1021 KiB | 18 Q