3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Simulated file data $data = <<<TAG Hunky Bill's Big Perogie / Pierogi Maker 9 4 10 5 5 1 2 1 TAG; // This allows us to create a stream pointing to a string. // This is only done to match the OP's code $csv_file = 'data://text/plain,'.$data; // We'll store items here temporarily $csv_items = []; if (($fp = fopen($csv_file, 'r'))) { while (!feof($fp)) { $item = fgets($fp); // Sanity check that we received something if (false === $item) { break; } // Trim both sides (unless you have a need for whitespace) $item = trim($item); // If we still have more than just an empty string if ($item) { // Append, optionally with quotes $csv_items[] = '"'.$item.'"'; } } fclose($fp); } // Create final string $csv_string = implode(',', $csv_items); var_dump($csv_string);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 35
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 11
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 11
Branch analysis from position: 32
Branch analysis from position: 11
Branch analysis from position: 27
Branch analysis from position: 35
filename:       /in/Chk2M
function name:  (null)
number of ops:  44
compiled vars:  !0 = $data, !1 = $csv_file, !2 = $csv_items, !3 = $fp, !4 = $item, !5 = $csv_string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, 'Hunky+Bill%27s+Big+Perogie+%2F+Pierogi+Maker%0A9%0A4%0A10%0A5%0A5%0A1%0A2%0A1'
   18     1        CONCAT                                           ~7      'data%3A%2F%2Ftext%2Fplain%2C', !0
          2        ASSIGN                                                   !1, ~7
   21     3        ASSIGN                                                   !2, <array>
   23     4        INIT_FCALL                                               'fopen'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 'r'
          7        DO_ICALL                                         $10     
          8        ASSIGN                                           ~11     !3, $10
          9      > JMPZ                                                     ~11, ->35
   24    10    > > JMP                                                      ->27
   26    11    >   INIT_FCALL                                               'fgets'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $12     
         14        ASSIGN                                                   !4, $12
   29    15        TYPE_CHECK                                    4          !4
         16      > JMPZ                                                     ~14, ->18
   30    17    > > JMP                                                      ->32
   34    18    >   INIT_FCALL                                               'trim'
         19        SEND_VAR                                                 !4
         20        DO_ICALL                                         $15     
         21        ASSIGN                                                   !4, $15
   37    22      > JMPZ                                                     !4, ->27
   39    23    >   CONCAT                                           ~18     '%22', !4
         24        CONCAT                                           ~19     ~18, '%22'
         25        ASSIGN_DIM                                               !2
         26        OP_DATA                                                  ~19
   24    27    >   INIT_FCALL                                               'feof'
         28        SEND_VAR                                                 !3
         29        DO_ICALL                                         $20     
         30        BOOL_NOT                                         ~21     $20
         31      > JMPNZ                                                    ~21, ->11
   42    32    >   INIT_FCALL                                               'fclose'
         33        SEND_VAR                                                 !3
         34        DO_ICALL                                                 
   46    35    >   INIT_FCALL                                               'implode'
         36        SEND_VAL                                                 '%2C'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $23     
         39        ASSIGN                                                   !5, $23
   48    40        INIT_FCALL                                               'var_dump'
         41        SEND_VAR                                                 !5
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.29 ms | 1022 KiB | 20 Q