fork download
  1. <?php
  2.  
  3. function get_attr_val_matches($tag, $subject)
  4. {
  5. $regex = '/"(\w+)"=(\w+)\s+(?=(?:"\w+"=\w+\s+)*' . strrev($tag) . '\{@)/';
  6. preg_match_all($regex, strrev($subject), $matches, PREG_SET_ORDER);
  7.  
  8. foreach ($matches as &$match)
  9. {
  10. $match = array_map(strrev, $match);
  11. $match = array($match[0], array_reverse(array_slice($match, 1)));
  12. }
  13.  
  14. return array_reverse($matches);
  15. }
  16.  
  17. $tag = 'articles';
  18. $subject = '@{articles mode="extrait" nb="3"}';
  19.  
  20. print_r(get_attr_val_matches($tag, $subject));
  21.  
  22. ?>
Success #stdin #stdout 0.03s 13064KB
stdin
Standard input is empty
stdout
    Array
(
    [0] => Array
        (
            [0] =>  mode="extrait"
            [1] => Array
                (
                    [0] => mode
                    [1] => extrait
                )

        )

    [1] => Array
        (
            [0] =>  nb="3"
            [1] => Array
                (
                    [0] => nb
                    [1] => 3
                )

        )

)