fork(2) download
  1. <?php
  2.  
  3. // set-up test string and final array
  4. $myString = "@test1: test1;@test2: test2;";
  5. $myArr = array();
  6.  
  7. // do the matching
  8. preg_match_all('/@([^\:]+)\:([^;]+);/', $myString, $matches);
  9.  
  10. // put elements of $matches in array here
  11. $actualMatches = count($matches) - 1;
  12. for ($i=0; $i<$actualMatches; $i++) {
  13. $myArr[$matches[1][$i]] = $matches[2][$i];
  14. }
  15. print_r($myArr);
  16.  
  17. ?>
Success #stdin #stdout 0.01s 13112KB
stdin
Standard input is empty
stdout
Array
(
    [test1] =>  test1
    [test2] =>  test2
)