Hello everyone,
I am developing something like a template language and I have found very strange error which as much as I try I just cannot get out of the way.
this is my haystack:
$haystack = <<<HERE
{hello /}
{call /}
{call /}
{debug /}
<p>content</p>
{loop:arr}
<h2 class=" ">{var name="title" /}</h2>
{if:loop.is_odd}
<ul>
{loop:arr2}
<li><strike>{good /}</strike> {bad /}</li>
{/loop:arr2}
</ul>
{/if:loop}
<p>written by {author /} at {var name="datum" type="date" /} </p>
<p>{ahoj /}</p>
{/loop:arr}
<p>{var name="date" type="date" /}aaa</p>
<a href="{url /}" title="bubububub" class="hopsa">blemblem</a>
{if:myvar2=="myvar2value"}<p>MYVAR2 = {myvar2 /}
{if:myvar.is_empty}bububukhohoho{/if:myvar}
hohohoho
{debug /}
{/if:myvar2}
block1content{author /}
{debug /}
HERE;
from where I want to get either combination of {something}content{/something} or {something /}
this is the regular expression which I am using to get that
$ldq = '{';
$rdq = '}';
preg_match_all("/{$ldq}([^\. ]{1,})([^\/}].*?)?{$rdq}(.*?){$ldq}\/\\1{$rdq}|{$ldq}([^\.} ]+)([^}]+)? \/{$rdq}/is", $haystack, $arr, PREG_SET_ORDER);
It works as I have posted it.
And now the problem: if I another {something /} in the haystack, it will just stop working and $arr will be an empty array. (And most stragely, it sometimes works if I find the right place, but more often it does not). If I replace for example {debug /} with another {something /}, it is always ok.
I am using the newest php as a module with apache on mac os.
Please, would you be so kind and try to help me? Please, tell me if I have forgotten some hidden option or if I have done some obvious mistake, because I am really desperate.