3v4l.org

run code in 300+ PHP versions simultaneously
<?php function fputcsvdata($dataArray,$delimiter,$enclosure) { // Write a line to a file // $filePointer = the file resource to write to // $dataArray = the data to write out // $delimeter = the field separator // Build the string $string = ""; // No leading delimiter $writeDelimiter = FALSE; foreach($dataArray as $dataElement) { // Replaces a double quote with two double quotes $dataElement=str_replace("\"", "\"\"", $dataElement); // Adds a delimiter before each field (except the first) if($writeDelimiter) $string .= $delimiter; // Encloses each field with $enclosure and adds it to the string $string .= $enclosure . $dataElement . $enclosure; // Delimiters are used every time except the first. $writeDelimiter = TRUE; } // end foreach($dataArray as $dataElement) // Append new line $string .= "\n"; return $string; } $data = array('this','is some', 'csv "stuff", you know.', 1, ''); var_dump(fputcsvdata($data, ',', '"')); //$out = fopen('php://output', 'w'); //fputcsv($out, $data); //fclose($out);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N0Sjd
function name:  (null)
number of ops:  10
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   ASSIGN                                                   !0, <array>
   38     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'fputcsvdata'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 '%2C'
          5        SEND_VAL                                                 '%22'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
   41     9      > RETURN                                                   1

Function fputcsvdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 15
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/N0Sjd
function name:  fputcsvdata
number of ops:  24
compiled vars:  !0 = $dataArray, !1 = $delimiter, !2 = $enclosure, !3 = $string, !4 = $writeDelimiter, !5 = $dataElement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   10     3        ASSIGN                                                   !3, ''
   13     4        ASSIGN                                                   !4, <false>
   14     5      > FE_RESET_R                                       $8      !0, ->20
          6    > > FE_FETCH_R                                               $8, !5, ->20
   17     7    >   INIT_FCALL                                               'str_replace'
          8        SEND_VAL                                                 '%22'
          9        SEND_VAL                                                 '%22%22'
         10        SEND_VAR                                                 !5
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !5, $9
   20    13      > JMPZ                                                     !4, ->15
         14    >   ASSIGN_OP                                     8          !3, !1
   23    15    >   CONCAT                                           ~12     !2, !5
         16        CONCAT                                           ~13     ~12, !2
         17        ASSIGN_OP                                     8          !3, ~13
   26    18        ASSIGN                                                   !4, <true>
   14    19      > JMP                                                      ->6
         20    >   FE_FREE                                                  $8
   30    21        ASSIGN_OP                                     8          !3, '%0A'
   33    22      > RETURN                                                   !3
   34    23*     > RETURN                                                   null

End of function fputcsvdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.5 ms | 1403 KiB | 18 Q