3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Simulated file data $data = <<<TAG Hunky Bill's Big Perogie / Pierogi Maker 9 4 10 5 5 1 2 1 TAG; // This allows us to create a stream pointing to a string. // This is only done to match the OP's code $csv_file = 'data://text/plain,'.$data; // We'll store items here temporarily $csv_items = []; if (($fp = fopen($csv_file, 'r'))) { while (!feof($fp)) { $item = fgets($fp); // Sanity check that we received something if (false === $item) { break; } // Trim both sides (unless you have a need for whitespace) $item = trim($item); // If we still have more than just an empty string if ($item) { // Append, optionally with quotes $csv_items[] = '"'.$item.'"'; } } fclose($fp); } // Create final string $csv_string = implode(',', $csv_items); var_dump($csv_string);
Output for git.master, git.master_jit, rfc.property-hooks
string(75) ""Hunky Bill's Big Perogie / Pierogi Maker","9","4","10","5","5","1","2","1""

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
148.98 ms | 405 KiB | 5 Q