fork(1) download
  1. <?php
  2. $str = "This is some random text, tag1{while this is inside a tag2{tag}}. This is some other text tag2{also with a tag tag3{inside} of it}.";
  3.  
  4. $re = "/\\b(\\w+)(?={((?:[^{}]+|{(?2)})*)})/";
  5. preg_match_all($re, $str, $m);
  6.  
  7. echo "* Tag names:\n";
  8. print_r($m[1]);
  9. echo "* Tag content:\n";
  10. print_r($m[2]);
  11. ?>
Success #stdin #stdout 0.02s 13112KB
stdin
Standard input is empty
stdout
* Tag names:
Array
(
    [0] => tag1
    [1] => tag2
    [2] => tag2
    [3] => tag3
)
* Tag content:
Array
(
    [0] => while this is inside a tag2{tag}
    [1] => tag
    [2] => also with a tag  tag3{inside} of it
    [3] => inside
)