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; if (!is_numeric($string)){ // 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/5GKGZ
function name:  (null)
number of ops:  10
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   38     0  E >   ASSIGN                                                   !0, <array>
   40     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                                                 
   43     9      > RETURN                                                   1

Function fputcsvdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 25
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 23
Branch analysis from position: 15
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/5GKGZ
function name:  fputcsvdata
number of ops:  29
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, ->25
          6    > > FE_FETCH_R                                               $8, !5, ->25
   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
   22    15    >   INIT_FCALL                                               'is_numeric'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $12     
         18        BOOL_NOT                                         ~13     $12
         19      > JMPZ                                                     ~13, ->23
   24    20    >   CONCAT                                           ~14     !2, !5
         21        CONCAT                                           ~15     ~14, !2
         22        ASSIGN_OP                                     8          !3, ~15
   28    23    >   ASSIGN                                                   !4, <true>
   14    24      > JMP                                                      ->6
         25    >   FE_FREE                                                  $8
   32    26        ASSIGN_OP                                     8          !3, '%0A'
   35    27      > RETURN                                                   !3
   36    28*     > RETURN                                                   null

End of function fputcsvdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.98 ms | 1403 KiB | 20 Q