3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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; var_dump($string); 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);
Output for 4.3.0 - 5.0.5, 5.1.1 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(0) "" string(7) ""this"," string(17) ""this","is some"," string(44) ""this","is some","csv ""stuff"", you know."," string(48) ""this","is some","csv ""stuff"", you know.","1"," string(51) ""this","is some","csv ""stuff"", you know.","1","" "
Output for 5.1.0
Fatal error: fatal flex scanner internal error--end of buffer missed in /in/jJUpc on line 43
Process exited with code 255.