<?php $str = <<< EOF STRING1 = "hello"; "good = bye" = "good1 = bye1"; NAME = "Your name is \"%@\""; "semicolon;confusion" = "I love semicolons; I hate semicolons"; "forget new line" = "forgot new line!"; EOF; if (preg_match_all('~(?<key>.+?)\s+=\s+(?=(?:(?:[^"]*"){2})*[^"]*$)(?<val>.+?)\s*(?<=");~', $str, $arr)) ?>
Standard input is empty
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!"
)
)