Coding help - [PHP - Preg]

I'm currently working on a template system like xenForo's, I've got my code working partly, I'm kinda new to the whole preg_match and preg_replace..

Right, I'll show you some code..

test.tpl:
Code:
<curve:if condition="test">
    Hai
    <curve:else>
        had
    </curve:else>
</curve:if>
However it's being translated to..
Code:
<curve:if condition="test">



    Hai


     <?php } else { ?>


        had


     <?php } else { ?>


</curve:if>

My PHP code is as follows:

PHP:
<?php
        private function _handleElse ( )
        {
            $find = '#(<curve:if)(.*)(<curve:else>|</curve:else>)(.*)</curve:if>#is';
            $input = $this->_outPut;
            while( ( bool ) preg_match( $find, $input ) )
            {
                $input = preg_replace
                (
                    $find,
                    '<curve:if$2 <?php } else { ?> $4</curve:if>',
                    $input
                );
            }
            echo $input;die;
        }
 
I dont know exactly what you're trying to do... but it appears you don't have a lot of understanding of Regular Expressions. In this case, I recommend you DON'T use them. Without a deep knowledge of regular expressions, they are very dangerous. In your code above, you have already made a major mishap with your use of greedy catch alls.
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

Not to mention, you won't be able to do nested conditions unless you program each one individually.
 
Top Bottom