3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<'EOD' 19018216307,Public,\,k]'=system1-system2,20230914143505.5,1-050000,No 32432151322,Public,blublabliblo,1324651651654.5,1-050000,No EOD; // change $filePath with the path of your file $filePath = 'data:text/plain;base64,' . base64_encode($str); if (false === $handle = fopen($filePath, 'r')) die("unable to open file $filePath"); $pattern = <<<'REGEX' ~(?nxx) (?# modifiers: - inline n: parenthesis act as a non-capturing group - inline xx: white-spaces are ignored even in character classes - global A: all the matches have to be contiguous ) # pattern ( (?!\A) , \K | \A ) # not at the start with a commas or at the start without [^ , \\ ]* ( \\ . [^ , \\ ]* )* # field content (all that isn't a comma nor # a backslash, except escaped characters) # final check ( \z (*:END) )? # define a marker if the end of the string is reached ~A REGEX; $result = []; // stream_get_line doesn't return the newline sequence (3rd parameter) // change it to \r\n or \r if needed, or use fgets and change \z with $ in the pattern while(false !== $line = stream_get_line($handle, 1024, "\n")) { if (preg_match_all($pattern, $line, $m) && isset($m['MARK'])) { $fields = array_map(fn($s) => strtr($s, ['\\\\' => '\\', '\\' => '']), $m[0]); $result[] = $fields; } else { die("unable to parse the following line:\n$line"); } } fclose($handle); print_r($result);
Output for 8.1.24 - 8.1.33, 8.2.11 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
Array ( [0] => Array ( [0] => 19018216307 [1] => Public [2] => ,k]'=system1-system2 [3] => 20230914143505.5 [4] => 1-050000 [5] => No ) [1] => Array ( [0] => 32432151322 [1] => Public [2] => blublabliblo [3] => 1324651651654.5 [4] => 1-050000 [5] => No ) )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
108.41 ms | 407 KiB | 5 Q