fork download
  1. <?php
  2.  
  3. $string = <<< EOF
  4. [WhiteTitle "GM"]
  5. [WhiteCountry "Cuba"]
  6. [BlackCountry "United States"]
  7. EOF;
  8.  
  9. $final = array();
  10.  
  11. preg_match_all('/\[(.*?)\s+(".*?")\]/m', $string, $matches, PREG_PATTERN_ORDER);
  12. for($i = 0; $i < count($matches[1]); $i++) {
  13. $final[$matches[1][$i]] = $matches[2][$i];
  14. }
  15.  
  16. print_r($final);
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
Array
(
    [WhiteTitle] => "GM"
    [WhiteCountry] => "Cuba"
    [BlackCountry] => "United States"
)