fork download
  1. <?php
  2.  
  3. $re = '~\s*("[^"\\\\]*(?:\\\\.[^\\\\"]*)*"|\'[^\'\\\\]*(?:\\\\.[^\\\\\']*)*\'|[^,]+),?~';
  4. $str = "\"test\", 'test2', \$test3, ?\"%A %d %B %Y\", \"foo,bar,foobar\"";
  5. preg_match_all($re, $str, $tokens);
  6. print_r($tokens[1]);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [0] => "test"
    [1] => 'test2'
    [2] => $test3
    [3] => ?"%A %d %B %Y"
    [4] => "foo,bar,foobar"
)