...

View Full Version : Weard IF Problem within a template system



barkermn01
08-22-2009, 06:44 PM
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


preg_match_all("/{if (.*[^\t]) (.*[^\t]) (.*[^,]), (.*[^,]), (.*[^}])}/", $this->content, $matches, PREG_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


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


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

barkermn01
08-23-2009, 01:48 PM
any one that can help?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum