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