fork download
  1. <?php
  2.  
  3. $re = '~(?:\G(?!^)\s+|\[shortcode\s+(\S+)\s+)([^\s=]+)="([^"]*)"~';
  4. $str = '[shortcode contact param1="test 2" param2="test1"]';
  5. $res = [];
  6. if (preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0)) {
  7. foreach ($matches as $m) {
  8. $res = array_merge($res, array_filter($m));
  9. }
  10. }
  11. print_r($res);
  12.  
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
Array
(
    [0] => contact
    [1] => param1
    [2] => test 2
    [3] => param2
    [4] => test1
)