3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Definir cabeçalhos para a codificação correta header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=exported_data.csv'); $fileName = $orderId . ".csv"; $file = fopen($fileName, "w+"); // Added + for read/write mode. // Escreve o BOM (Byte Order Mark) para indicar UTF-8 fputs($file, chr(0xEF) . chr(0xBB) . chr(0xBF)); // Write the header row $headerRow = ["ID", "Item", "Price", "Amount", "Total", "Description"]; fputcsv($file, $headerRow); // Loop over each item in the $items array foreach ($items as $item) { // Build an array containing information about the item $itemArray = [ $item->ID, $item->Name, $item->Price . $currency, $item->Amount, $item->Price * $item->Amount . $currency, $item->Description ]; // Write the item information to the file fputcsv($file, $itemArray); } // Write the total row $totalRow = ["Grand total", "", "", $totalAmount, $total . $currency, ""]; fputcsv($file, $totalRow); // Close the file fclose($file); $fileUrl = "https://" . $_SERVER['HTTP_HOST'] . "/" . $fileName;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 46
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 46
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
filename:       /in/LUY5X
function name:  (null)
number of ops:  69
compiled vars:  !0 = $fileName, !1 = $orderId, !2 = $file, !3 = $headerRow, !4 = $items, !5 = $item, !6 = $itemArray, !7 = $currency, !8 = $totalRow, !9 = $totalAmount, !10 = $total, !11 = $fileUrl
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   INIT_FCALL                                               'header'
          1        SEND_VAL                                                 'Content-Type%3A+text%2Fcsv%3B+charset%3Dutf-8'
          2        DO_ICALL                                                 
    5     3        INIT_FCALL                                               'header'
          4        SEND_VAL                                                 'Content-Disposition%3A+attachment%3B+filename%3Dexported_data.csv'
          5        DO_ICALL                                                 
    6     6        CONCAT                                           ~14     !1, '.csv'
          7        ASSIGN                                                   !0, ~14
    7     8        INIT_FCALL                                               'fopen'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 'w%2B'
         11        DO_ICALL                                         $16     
         12        ASSIGN                                                   !2, $16
   10    13        INIT_FCALL                                               'fputs'
         14        SEND_VAR                                                 !2
         15        SEND_VAL                                                 '%EF%BB%BF'
         16        DO_ICALL                                                 
   13    17        ASSIGN                                                   !3, <array>
   14    18        INIT_FCALL                                               'fputcsv'
         19        SEND_VAR                                                 !2
         20        SEND_VAR                                                 !3
         21        DO_ICALL                                                 
   17    22      > FE_RESET_R                                       $21     !4, ->46
         23    > > FE_FETCH_R                                               $21, !5, ->46
   20    24    >   FETCH_OBJ_R                                      ~22     !5, 'ID'
         25        INIT_ARRAY                                       ~23     ~22
   21    26        FETCH_OBJ_R                                      ~24     !5, 'Name'
         27        ADD_ARRAY_ELEMENT                                ~23     ~24
   22    28        FETCH_OBJ_R                                      ~25     !5, 'Price'
         29        CONCAT                                           ~26     ~25, !7
         30        ADD_ARRAY_ELEMENT                                ~23     ~26
   23    31        FETCH_OBJ_R                                      ~27     !5, 'Amount'
         32        ADD_ARRAY_ELEMENT                                ~23     ~27
   24    33        FETCH_OBJ_R                                      ~28     !5, 'Price'
         34        FETCH_OBJ_R                                      ~29     !5, 'Amount'
         35        MUL                                              ~30     ~28, ~29
         36        CONCAT                                           ~31     ~30, !7
         37        ADD_ARRAY_ELEMENT                                ~23     ~31
   25    38        FETCH_OBJ_R                                      ~32     !5, 'Description'
         39        ADD_ARRAY_ELEMENT                                ~23     ~32
   19    40        ASSIGN                                                   !6, ~23
   28    41        INIT_FCALL                                               'fputcsv'
         42        SEND_VAR                                                 !2
         43        SEND_VAR                                                 !6
         44        DO_ICALL                                                 
   17    45      > JMP                                                      ->23
         46    >   FE_FREE                                                  $21
   32    47        INIT_ARRAY                                       ~35     'Grand+total'
         48        ADD_ARRAY_ELEMENT                                ~35     ''
         49        ADD_ARRAY_ELEMENT                                ~35     ''
         50        ADD_ARRAY_ELEMENT                                ~35     !9
         51        CONCAT                                           ~36     !10, !7
         52        ADD_ARRAY_ELEMENT                                ~35     ~36
         53        ADD_ARRAY_ELEMENT                                ~35     ''
         54        ASSIGN                                                   !8, ~35
   33    55        INIT_FCALL                                               'fputcsv'
         56        SEND_VAR                                                 !2
         57        SEND_VAR                                                 !8
         58        DO_ICALL                                                 
   36    59        INIT_FCALL                                               'fclose'
         60        SEND_VAR                                                 !2
         61        DO_ICALL                                                 
   38    62        FETCH_R                      global              ~40     '_SERVER'
         63        FETCH_DIM_R                                      ~41     ~40, 'HTTP_HOST'
         64        CONCAT                                           ~42     'https%3A%2F%2F', ~41
         65        CONCAT                                           ~43     ~42, '%2F'
         66        CONCAT                                           ~44     ~43, !0
         67        ASSIGN                                                   !11, ~44
   39    68      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.75 ms | 1435 KiB | 18 Q