Lol, well I am sure it is majorly over complicated, just though someone might wanna see itPHP Code:
<?php
ob_start();
?>
{if $Lol="Hello"}
true
{if:else}
false
{/if}
<?php
$Content = ob_get_contents();
ob_end_clean();
$Lol = "Hello";
if(preg_match('@^(?:{if )?([^}]+)@i', $Content, $Statement)){
if(preg_match("/=/i", $Statement[1])){
$Data = explode("=", $Statement[1]);
for($i = 0; $i < Count($Data); $i++){
$Data[$i] = trim($Data[$i], " ");
if(isVariable($Data[$i])){
$Data[$i] = ltrim($Data[$i], "$");
if(isset(${$Data[$i]})){
$Data[$i] = ${$Data[$i]};
}
}else{
$Data[$i] = trimString($Data[$i]);
}
}
if(strpos($Content, "{if:") !== false && strpos($Content, "{if:") < strpos($Content, "{/if}")){
if(substr($Content, strpos($Content, "{if:")+4, 4) == "else"){
if($Data[0] == $Data[1]){
echo substr($Content, (strpos($Content, $Statement[1] . "}\r\n") + strlen($Statement[1] . "}\r\n")), (strpos($Content, "{if:else}") - (strpos($Content, $Statement[1] . "}\r\n") + strlen($Statement[1] . "}\r\n"))));
}else{
echo substr($Content, (strpos($Content, "{if:else}\r\n") + strlen("{if:else}\r\n")), (strpos($Content, "{/if}") - (strpos($Content, "{if:else}\r\n") + strlen("{if:else}\r\n"))));
}
}
}else{
if($Data[0] == $Data[1]){
echo substr($Content, (strpos($Content, $Statement[1] . "}\r\n") + strlen($Statement[1] . "}\r\n")), (strpos($Content, "{/if}") - (strpos($Content, $Statement[1] . "}\r\n") + strlen($Statement[1] . "}\r\n"))));
}
}
}
}
function isVariable($String){
if(strpos($String, "$") !== false){
return true;
}
return false;
}
function trimString($String){
$String = trim($String, '"');
$String = trim($String, "'");
return $String;
}
?>
Results 1 to 12 of 12
Thread: PHP Test Code
- 18 Nov. 2009 09:21am #1
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 500.00
PHP Test Code
Last edited by Chris; 18 Nov. 2009 at 09:27am.
- 18 Nov. 2009 05:17pm #2
What are you testing with this? It's so hard to follow by just looking at it. XD
- 18 Nov. 2009 06:01pm #3
- Join Date
- Nov. 2009
- Location
- In CL0V3R's Smoke Ball
- Posts
- 1,010
- Reputation
- 28
- LCash
- 200.00
Whats this code for O_o
- 18 Nov. 2009 06:02pm #4
yea what is this code?
- 18 Nov. 2009 10:31pm #5
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 200.00
Turns text into a if or if/else statement.
So it will parse
Code:{if $Lol="Hello"} true {if:else} false {/if}
and then display the proper data.
- 19 Nov. 2009 02:44am #6
I'd stick with using PHP instead of custom code. CodeIgnitor had a small write up on this and found that parsing custom code to PHP causes much lag, when the much faster alternative of straight PHP code isn't any more difficult to understand.
- 19 Nov. 2009 03:59am #7
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 200.00
- 19 Nov. 2009 06:34am #8
Would you mind elaborating on the difference between @ boundaries in RegEx and / boundaries?
- 19 Nov. 2009 06:48am #9
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 200.00
- 19 Nov. 2009 07:43am #10
Ah.
I noticed you switched between them:
PHP Code:if(preg_match('@^(?:{if )?([^}]+)@i', $Content, $Statement)){
if(preg_match("/=/i", $Statement[1])){
- 19 Nov. 2009 08:05am #11
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 200.00
- 19 Nov. 2009 08:23am #12
Well then, perhaps like in PHP itself @ means to not give an error. If a symbol is giving you problems, escape it.
You likely could have changed < and > to \< and \> and fixed your problem. If you hadn't tried that.