fork download
  1. <?php
  2. $str = '[name:roccos] [phone:123324324] [tags:abc def ghi] [id:value]';
  3. preg_match_all('/\[(.*?):(.*?)\]/', $str, $matches, PREG_SET_ORDER);
  4. $data = array();
  5.  
  6. foreach($matches as $match) {
  7. $data[$match[1]] = $match[2];
  8. }
  9.  
  10. print_r($data);
  11. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [name] => roccos
    [phone] => 123324324
    [tags] => abc def ghi
    [id] => value
)