fork download
  1. <?php
  2. $str = <<< EOF
  3. STRING1 = "hello";
  4. "good = bye" = "good1 = bye1";
  5. NAME = "Your name is \"%@\"";
  6. "semicolon;confusion" = "I love semicolons; I hate semicolons"; "forget new line" = "forgot new line!";
  7. EOF;
  8.  
  9. if (preg_match_all('~(?<key>.+?)\s+=\s+(?=(?:(?:[^"]*"){2})*[^"]*$)(?<val>.+?)\s*(?<=");~', $str, $arr))
  10. print_r($arr);
  11. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => STRING1 = "hello";
            [1] => "good = bye" = "good1 = bye1";
            [2] => NAME = "Your name is \"%@\"";
            [3] => "semicolon;confusion" = "I love semicolons; I hate semicolons";
            [4] =>  "forget new line" = "forgot new line!";
        )

    [key] => Array
        (
            [0] => STRING1
            [1] => "good = bye"
            [2] => NAME
            [3] => "semicolon;confusion"
            [4] =>  "forget new line"
        )

    [1] => Array
        (
            [0] => STRING1
            [1] => "good = bye"
            [2] => NAME
            [3] => "semicolon;confusion"
            [4] =>  "forget new line"
        )

    [val] => Array
        (
            [0] => "hello"
            [1] => "good1 = bye1"
            [2] => "Your name is \"%@\""
            [3] => "I love semicolons; I hate semicolons"
            [4] => "forgot new line!"
        )

    [2] => Array
        (
            [0] => "hello"
            [1] => "good1 = bye1"
            [2] => "Your name is \"%@\""
            [3] => "I love semicolons; I hate semicolons"
            [4] => "forgot new line!"
        )

)