3v4l.org

run code in 300+ PHP versions simultaneously
<?php $temp = tempnam(sys_get_temp_dir(), 'csv_bug'); file_put_contents($temp, <<<'CSV' first,second foo,bar "foo baz",bar baz,bar CSV ); $expected = array( array('first', 'second'), array('foo', 'bar'), array("foo\nbaz", 'bar'), array('baz', 'bar'), ); $cases = array( 'drop newline' => \SplFileObject::DROP_NEW_LINE, 'skip empty' => \SplFileObject::SKIP_EMPTY, 'skip empty + read ahead' => \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD, 'drop newline + read ahead' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD, 'drop newline + skip empty' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY, 'all' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD, ); foreach ($cases as $name => $flags) { $file = new SplFileObject($temp); $file->setFlags($flags | \SplFileObject::READ_CSV); echo $name, "\n"; var_dump(iterator_to_array($file, false)); } var_dump('expected', $expected);
Output for git.master, git.master_jit, rfc.property-hooks
drop newline array(5) { [0]=> array(2) { [0]=> string(5) "first" [1]=> string(6) "second" } [1]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } [2]=> array(1) { [0]=> NULL } [3]=> array(2) { [0]=> string(7) "foo baz" [1]=> string(3) "bar" } [4]=> array(2) { [0]=> string(3) "baz" [1]=> string(3) "bar" } } skip empty array(5) { [0]=> array(2) { [0]=> string(5) "first" [1]=> string(6) "second" } [1]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } [2]=> array(1) { [0]=> NULL } [3]=> array(2) { [0]=> string(7) "foo baz" [1]=> string(3) "bar" } [4]=> array(2) { [0]=> string(3) "baz" [1]=> string(3) "bar" } } skip empty + read ahead array(5) { [0]=> array(2) { [0]=> string(5) "first" [1]=> string(6) "second" } [1]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } [2]=> array(1) { [0]=> NULL } [3]=> array(2) { [0]=> string(7) "foo baz" [1]=> string(3) "bar" } [4]=> array(2) { [0]=> string(3) "baz" [1]=> string(3) "bar" } } drop newline + read ahead array(5) { [0]=> array(2) { [0]=> string(5) "first" [1]=> string(6) "second" } [1]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } [2]=> array(1) { [0]=> NULL } [3]=> array(2) { [0]=> string(7) "foo baz" [1]=> string(3) "bar" } [4]=> array(2) { [0]=> string(3) "baz" [1]=> string(3) "bar" } } drop newline + skip empty array(4) { [0]=> array(2) { [0]=> string(5) "first" [1]=> string(6) "second" } [1]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } [2]=> array(2) { [0]=> string(7) "foo baz" [1]=> string(3) "bar" } [3]=> array(2) { [0]=> string(3) "baz" [1]=> string(3) "bar" } } all array(4) { [0]=> array(2) { [0]=> string(5) "first" [1]=> string(6) "second" } [1]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } [2]=> array(2) { [0]=> string(7) "foo baz" [1]=> string(3) "bar" } [3]=> array(2) { [0]=> string(3) "baz" [1]=> string(3) "bar" } } string(8) "expected" array(4) { [0]=> array(2) { [0]=> string(5) "first" [1]=> string(6) "second" } [1]=> array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } [2]=> array(2) { [0]=> string(7) "foo baz" [1]=> string(3) "bar" } [3]=> array(2) { [0]=> string(3) "baz" [1]=> string(3) "bar" } }

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:
57.56 ms | 409 KiB | 8 Q