fork(2) download
  1. <?php
  2.  
  3. $test = <<<_END
  4. intKey=6 , floatKey=12.34, simpleString=simple_value , booleanValue=true ,
  5. quotedString="test\"value", singlQuoted='singlQuotedValue',nullValue=null
  6. _END;
  7.  
  8. function parseString($incomingString) {
  9. $result = [];
  10. $parts = preg_split('/,/u', $incomingString, 0, PREG_SPLIT_NO_EMPTY);
  11.  
  12. foreach ($parts as $part) {
  13. $tempString = trim($part);
  14. $brokenString = preg_split('/=/u', $tempString, 0, PREG_SPLIT_NO_EMPTY);
  15. $result[$brokenString[0]] = $brokenString[1];
  16. }
  17. return $result;
  18. }
  19.  
  20. $a = parseString($test);
  21. print_r($a);
  22.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [intKey] => 6
    [floatKey] => 12.34
    [simpleString] => simple_value
    [booleanValue] => true
    [quotedString] => "test\"value"
    [singlQuoted] => 'singlQuotedValue'
    [nullValue] => null
)