fork download
  1. <?php
  2.  
  3. $string = "aa | bb | \"cc | dd\" | 'ee | ff'";
  4.  
  5. $pattern = '~([\'"]).*?\1(*SKIP)(*FAIL)|\s*\|\s*~';
  6.  
  7. $splitted = preg_split($pattern, $string);
  8. print_r($splitted);
  9. ?>
Success #stdin #stdout 0.02s 25904KB
stdin
Standard input is empty
stdout
Array
(
    [0] => aa
    [1] => bb
    [2] => "cc | dd"
    [3] => 'ee | ff'
)