3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * You can open a sample spreadsheet at https://goo.gl/j50MKc * You can download a sample CSV at https://goo.gl/H4ni63 */ $payload = '"Hello\", World!'; $rfcCsv = '"""Hello\"", World!"'; //Contents of https://goo.gl/H4ni63 $actualRfc = str_getcsv($rfcCsv, ',', '"', '"'); echo "READING RFC CSV\n"; echo "---------------\n"; echo "To read a well formatted CSV, you must use the `double-quote` char as enclosure and\n"; echo " as escape\n"; echo sprintf("Expected: %s\n", $payload); echo sprintf("Actual : %s\n", $actualRfc[0]); echo "Equals? "; var_dump($payload === $actualRfc[0]); echo "\n\n================================================================================\n\n"; $handler = fopen('php://temp', 'w+'); echo "WRITING\n"; echo "-------\n"; if (PHP_VERSION_ID < 50504 || (defined('HHVM_VERSION_ID') && HHVM_VERSION_ID < 31100)) { // There is NO support for escape param fputcsv($handler, array($payload), ',', '"'); } else { // There is support for escape param fputcsv($handler, array($payload), ',', '"', '"'); } rewind($handler); $actual = rtrim(fgets($handler, 4096), "\n"); echo "There is no way to write a well formatted CSV even. The support for the escape param\n"; echo " in the fputcsv function do not fix the invalid format.\n"; echo sprintf("Expected: %s\n", $rfcCsv); echo sprintf("Actual : %s\n", $actual); echo "Equals? "; var_dump($rfcCsv === $actual); echo "\n\n================================================================================\n\n"; $actualPhp = str_getcsv($actual, ',', '"', '"'); echo "READING PHP CSV\n"; echo "---------------\n"; echo "If you read a PHP formatted CSV using use the `double-quote` char as enclosure and\n"; echo " as escape, the result is not the expected one.\n"; echo sprintf("Expected: %s\n", $payload); echo sprintf("Actual : %s\n", $actualPhp[0]); echo "Equals? "; var_dump($payload === $actualPhp[0]); echo "\n\n================================================================================\n\n";
Output for 5.5.4 - 5.5.36, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.21, 7.4.0 - 7.4.10, 8.0.0alpha1 - beta3
READING RFC CSV --------------- To read a well formatted CSV, you must use the `double-quote` char as enclosure and as escape Expected: "Hello\", World! Actual : "Hello\", World! Equals? bool(true) ================================================================================ WRITING ------- There is no way to write a well formatted CSV even. The support for the escape param in the fputcsv function do not fix the invalid format. Expected: """Hello\"", World!" Actual : ""Hello\", World!" Equals? bool(false) ================================================================================ READING PHP CSV --------------- If you read a PHP formatted CSV using use the `double-quote` char as enclosure and as escape, the result is not the expected one. Expected: "Hello\", World! Actual : Hello\" Equals? bool(false) ================================================================================
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.3
READING RFC CSV --------------- To read a well formatted CSV, you must use the `double-quote` char as enclosure and as escape Expected: "Hello\", World! Actual : "Hello\", World! Equals? bool(true) ================================================================================ WRITING ------- There is no way to write a well formatted CSV even. The support for the escape param in the fputcsv function do not fix the invalid format. Expected: """Hello\"", World!" Actual : """Hello\", World!" Equals? bool(false) ================================================================================ READING PHP CSV --------------- If you read a PHP formatted CSV using use the `double-quote` char as enclosure and as escape, the result is not the expected one. Expected: "Hello\", World! Actual : "Hello\ Equals? bool(false) ================================================================================
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Fatal error: Call to undefined function str_getcsv() in /in/NnHp4 on line 10
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: str_getcsv() in /in/NnHp4 on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: str_getcsv() in /in/NnHp4 on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: str_getcsv() in /in/NnHp4 on line 10