fork download
  1. <?php
  2. $v = "key: [value1, value2, value3]";
  3. $pattern = "/([^\s:]+)\s*:\s*\[([^\]]*)\]/";
  4.  
  5. preg_match($pattern, $v, $matches);
  6. $matches[2] = preg_split("/,\s*/", $matches[2]);
  7.  
  8. echo("key: " . $matches[1] . "\n");
  9. echo("values: ");
  10. var_dump($matches[2]);
  11. ?>
  12.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
key: key
values: array(3) {
  [0]=>
  string(6) "value1"
  [1]=>
  string(6) "value2"
  [2]=>
  string(6) "value3"
}