3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string ="Folder1/Folder2/Folder3/filename1\n"; $string .=" Folder1/Folder2/Folder3/filename2\n"; $string .=" Folder4/Folder2/Folder3/filename3\n"; $string .=" filename4\n"; $string .=" Folder5/filename5\n"; $string .=" Folder5/Folder6/filename6\n"; $parsable = ''; foreach (explode("\n", trim($string)) as $path) { // cut off final newline and explode $entries = explode("/", trim($path)); // cut off leading spaces and explode $file = array_splice($entries, -1); // separate filename from path $path = array_reduce($entries, function($carry, $v) { return $carry."[$v]"; // wrap each folder in square brackets }); $parsable .= "path{$path}[]={$file[0]}&"; // build parsable string (final trailing & will be ignored) } echo $parsable,"\n\n"; parse_str($parsable, $out); var_export($out);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 43
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 43
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/UGK0l
function name:  (null)
number of ops:  54
compiled vars:  !0 = $string, !1 = $parsable, !2 = $path, !3 = $entries, !4 = $file, !5 = $out
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'Folder1%2FFolder2%2FFolder3%2Ffilename1%0A'
    3     1        ASSIGN_OP                                     8          !0, '+Folder1%2FFolder2%2FFolder3%2Ffilename2%0A'
    4     2        ASSIGN_OP                                     8          !0, '+Folder4%2FFolder2%2FFolder3%2Ffilename3%0A'
    5     3        ASSIGN_OP                                     8          !0, '+filename4%0A'
    6     4        ASSIGN_OP                                     8          !0, '+Folder5%2Ffilename5%0A'
    7     5        ASSIGN_OP                                     8          !0, '+Folder5%2FFolder6%2Ffilename6%0A'
    9     6        ASSIGN                                                   !1, ''
   10     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%0A'
          9        INIT_FCALL                                               'trim'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $13     
         12        SEND_VAR                                                 $13
         13        DO_ICALL                                         $14     
         14      > FE_RESET_R                                       $15     $14, ->43
         15    > > FE_FETCH_R                                               $15, !2, ->43
   11    16    >   INIT_FCALL                                               'explode'
         17        SEND_VAL                                                 '%2F'
         18        INIT_FCALL                                               'trim'
         19        SEND_VAR                                                 !2
         20        DO_ICALL                                         $16     
         21        SEND_VAR                                                 $16
         22        DO_ICALL                                         $17     
         23        ASSIGN                                                   !3, $17
   12    24        INIT_FCALL                                               'array_splice'
         25        SEND_REF                                                 !3
         26        SEND_VAL                                                 -1
         27        DO_ICALL                                         $19     
         28        ASSIGN                                                   !4, $19
   13    29        INIT_FCALL                                               'array_reduce'
         30        SEND_VAR                                                 !3
         31        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FUGK0l%3A13%240'
   15    32        SEND_VAL                                                 ~21
         33        DO_ICALL                                         $22     
   13    34        ASSIGN                                                   !2, $22
   16    35        ROPE_INIT                                     5  ~26     'path'
         36        ROPE_ADD                                      1  ~26     ~26, !2
         37        ROPE_ADD                                      2  ~26     ~26, '%5B%5D%3D'
         38        FETCH_DIM_R                                      ~24     !4, 0
         39        ROPE_ADD                                      3  ~26     ~26, ~24
         40        ROPE_END                                      4  ~25     ~26, '%26'
         41        ASSIGN_OP                                     8          !1, ~25
   10    42      > JMP                                                      ->15
         43    >   FE_FREE                                                  $15
   18    44        ECHO                                                     !1
         45        ECHO                                                     '%0A%0A'
   19    46        INIT_FCALL                                               'parse_str'
         47        SEND_VAR                                                 !1
         48        SEND_REF                                                 !5
         49        DO_ICALL                                                 
   20    50        INIT_FCALL                                               'var_export'
         51        SEND_VAR                                                 !5
         52        DO_ICALL                                                 
         53      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FUGK0l%3A13%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UGK0l
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $carry, !1 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        ROPE_INIT                                     3  ~3      '%5B'
          3        ROPE_ADD                                      1  ~3      ~3, !1
          4        ROPE_END                                      2  ~2      ~3, '%5D'
          5        CONCAT                                           ~5      !0, ~2
          6      > RETURN                                                   ~5
   15     7*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FUGK0l%3A13%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.7 ms | 1400 KiB | 25 Q