fork(1) download
  1. <?php
  2. // http://stackoverflow.com/q/32969465/5290909
  3.  
  4. $pattern = '@([#$])|[{}/]+@';
  5. $text = '{$gallery#pager/collectionName/imageName/manual/no_effect/foo1/foo2/.../fooN}';
  6.  
  7. $result = preg_split($pattern, $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
  8.  
  9. //Validate
  10. $valid = ($result[0] == '$') && ($result[2] == '#');
  11.  
  12. if ($valid) {
  13. var_dump($result);
  14. }
  15.  
  16. ?>
Success #stdin #stdout 0.02s 52480KB
stdin
Standard input is empty
stdout
array(12) {
  [0]=>
  string(1) "$"
  [1]=>
  string(7) "gallery"
  [2]=>
  string(1) "#"
  [3]=>
  string(5) "pager"
  [4]=>
  string(14) "collectionName"
  [5]=>
  string(9) "imageName"
  [6]=>
  string(6) "manual"
  [7]=>
  string(9) "no_effect"
  [8]=>
  string(4) "foo1"
  [9]=>
  string(4) "foo2"
  [10]=>
  string(3) "..."
  [11]=>
  string(4) "fooN"
}