3v4l.org

run code in 300+ PHP versions simultaneously
<?php function csvToJson($fname) { //read csv headers $key = str_getcsv($fname,"1024"," "); // parse csv rows into array $json = array(); while ($row = str_getcsv($fname,"1024"," ")) { $json[] = array_combine($key, $row); } // release file handle fclose($fp); // encode array to json return json_encode($json); } $fname = "Quote Author You never know if you can actually do something against all odds until you actually do it. Abby Wambach (Soccer) Always work hard, never give up, and fight until the end because it&#39;s never really over until the whistle blows. Alex Morgan (Soccer) No matter what accomplishments you make, somebody helped you. Althea Gibson (Tennis, Golf) You can&#39;t always be the best. You have to remember that everyone makes mistakes sometimes. Aly Raisman (Gymnastics)"; echo csvToJson($fname);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZPIB7
function name:  (null)
number of ops:  6
compiled vars:  !0 = $fname
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                   !0, 'Quote%09Author%0AYou+never+know+if+you+can+actually+do+something+against+all+odds+until+you+actually+do+it.%09Abby+Wambach+%28Soccer%29%0AAlways+work+hard%2C+never+give+up%2C+and+fight+until+the+end+because+it%26%2339%3Bs+never+really+over+until+the+whistle+blows.%09Alex+Morgan+%28Soccer%29%0ANo+matter+what+accomplishments+you+make%2C+somebody+helped+you.%09Althea+Gibson+%28Tennis%2C+Golf%29%0AYou+can%26%2339%3Bt+always+be+the+best.+You+have+to+remember+that+everyone+makes+mistakes+sometimes.%09Aly+Raisman+%28Gymnastics%29'
   26     1        INIT_FCALL                                               'csvtojson'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function csvtojson:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 9
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 22, Position 2 = 9
Branch analysis from position: 22
Branch analysis from position: 9
filename:       /in/ZPIB7
function name:  csvToJson
number of ops:  30
compiled vars:  !0 = $fname, !1 = $key, !2 = $json, !3 = $row, !4 = $fp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'str_getcsv'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 '1024'
          4        SEND_VAL                                                 '++++'
          5        DO_ICALL                                         $5      
          6        ASSIGN                                                   !1, $5
    8     7        ASSIGN                                                   !2, <array>
    9     8      > JMP                                                      ->15
   10     9    >   INIT_FCALL                                               'array_combine'
         10        SEND_VAR                                                 !1
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $9      
         13        ASSIGN_DIM                                               !2
         14        OP_DATA                                                  $9
    9    15    >   INIT_FCALL                                               'str_getcsv'
         16        SEND_VAR                                                 !0
         17        SEND_VAL                                                 '1024'
         18        SEND_VAL                                                 '++++'
         19        DO_ICALL                                         $10     
         20        ASSIGN                                           ~11     !3, $10
         21      > JMPNZ                                                    ~11, ->9
   14    22    >   INIT_FCALL                                               'fclose'
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                                 
   17    25        INIT_FCALL                                               'json_encode'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                         $13     
         28      > RETURN                                                   $13
   18    29*     > RETURN                                                   null

End of function csvtojson

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.41 ms | 1403 KiB | 22 Q