Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts

    Weard IF Problem within a template system

    Hello all,

    Ok this one is a weard one for me ok i have a template class and im building in if's to it so this is my code
    $core is my testing class print_p just dose print_r() rapped in <pre> tags
    PHP Code:
    preg_match_all("/{if (.*[^\t]) (.*[^\t]) (.*[^,]), (.*[^,]), (.*[^}])}/"$this->content$matchesPREG_SET_ORDER); 
            
    $core->print_p($matches);
            foreach(
    $matches as $key => $val){
                
    $replace "";
                switch(
    $val[2]){
                    case 
    "==":
                        if(
    $val[1] == $val[2]){$replace $val[4];}else{$replace $val[5];};
                    break;
                    case 
    "!=":
                        if(
    $val[1] != $val[2]){$replace $val[4];}else{$replace $val[5];};
                    break;
                    case 
    "<":
                        if(
    $val[1] < $val[2]){$replace $val[4];}else{$replace $val[5];};
                    break;
                    case 
    "<=":
                        if(
    $val[1] <= $val[2]){$replace $val[4];}else{$replace $val[5];};
                    break;
                    case 
    ">":
                        if(
    $val[1] > $val[2]){$replace $val[4];}else{$replace $val[5];};
                    break;
                    case 
    ">=":
                        if(
    $val[1] >= $val[2]){$replace $val[4];}else{$replace $val[5];};
                    break;
                }
                 
    $this->content str_replace($val[0], $replace$this->content);
            } 
    So this all seems correct to me but this is my results
    Code:
    Array
    (
        [0] => Array
            (
                [0] => {if 1 != 1, true, false}
                [1] => 1
                [2] => !=
                [3] => 1
                [4] => true
                [5] => false
            )
    
    )
    true
    
    OR 
    
    Array
    (
        [0] => Array
            (
                [0] => {if 1 == 1, true, false}
                [1] => 1
                [2] => ==
                [3] => 1
                [4] => true
                [5] => false
            )
    
    )
    false
    But what's confusing me is this
    Code:
    Array
    (
        [0] => Array
            (
                [0] => {if 1 != 2, true, false}
                [1] => 1
                [2] => !=
                [3] => 2
                [4] => true
                [5] => false
            )
    
    )
    true
    
    OR 
    
    Array
    (
        [0] => Array
            (
                [0] => {if 1 == 2, true, false}
                [1] => 1
                [2] => ==
                [3] => 2
                [4] => true
                [5] => false
            )
    
    )
    false
    If any one could provide a solution or explanation please help

    Thanks Martin Barker
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    any one that can help?
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •