<?php
# The input text:
$str = <<<EOF
Some text
{@if condtwo}
{@if condone}
show this if condone is true
{!if}
other contents
{!if}
Some other text
EOF;
# Find the match:
if(preg_match('/{@if(.+?)}(((?>[^{}]+)|(?R))*){!if}/si', $str, $matches)) { # The contents are stored at index 2.
echo $matches[2];
}
?>
PD9waHAKIyBUaGUgaW5wdXQgdGV4dDoKJHN0ciA9IDw8PEVPRgpTb21lIHRleHQKCntAaWYgY29uZHR3b30KICAgIHtAaWYgY29uZG9uZX0KICAgICAgICBzaG93IHRoaXMgaWYgY29uZG9uZSBpcyB0cnVlCiAgICB7IWlmfQoKCW90aGVyIGNvbnRlbnRzCnshaWZ9CgpTb21lIG90aGVyIHRleHQKRU9GOwoKIyBGaW5kIHRoZSBtYXRjaDoKaWYocHJlZ19tYXRjaCgnL3tAaWYoLis/KX0oKCg/Pltee31dKyl8KD9SKSkqKXshaWZ9L3NpJywgJHN0ciwgJG1hdGNoZXMpKSB7CiAgICAjIFRoZSBjb250ZW50cyBhcmUgc3RvcmVkIGF0IGluZGV4IDIuCiAgICBlY2hvICRtYXRjaGVzWzJdOwp9Cj8+