fork download
  1. <?php
  2. # The input text:
  3. $str = <<<EOF
  4. Some text
  5.  
  6. {@if condtwo}
  7.   {@if condone}
  8.   show this if condone is true
  9.   {!if}
  10.  
  11. other contents
  12. {!if}
  13.  
  14. Some other text
  15. EOF;
  16.  
  17. # Find the match:
  18. if(preg_match('/{@if(.+?)}(((?>[^{}]+)|(?R))*){!if}/si', $str, $matches)) {
  19. # The contents are stored at index 2.
  20. echo $matches[2];
  21. }
  22. ?>
Success #stdin #stdout 0.03s 13064KB
stdin
Standard input is empty
stdout
    {@if condone}
        show this if condone is true
    {!if}

	other contents