Forum Moderators: coopster

Message Too Old, No Replies

<if> tags

         

McBlack

8:58 pm on Dec 24, 2008 (gmt 0)

10+ Year Member



hello everybody...

I'm trying to make a log in system - and I don't know how to parse if tags correctly.. I've done something temporary but it brings up a lot of bugs.

I want to be able to do something like this

<if="arg">
true
<else>
false
</else>
</if>

anyone know how to do this?

Mahabub

6:11 am on Dec 25, 2008 (gmt 0)

10+ Year Member



McBlack,

Your If/Else Condition not look like php if/else. Look at the below one.

if(Some Condition){

// If the Condition true execute this block of code
}

else{
//if condition is false execute this block of code
}

Other wise you can do the below one

if(condition){
// Some Code
}
else if(condition){
// Some Code
}
else if(condition){
// Some Code
}
else{
// Some COde
}

for More Information please look at PHP Manual.

Thanks
Mahabub

McBlack

5:47 pm on Dec 25, 2008 (gmt 0)

10+ Year Member



yes - I know. I guess I should have explained more...

Since I'm making a templating system, I want it to parse the if tags in HTML <if> tags

Sort of like this -

replace <if="(.+?)"> with if( $1 ) {
replace <else /> with } else {
replace </if> with }

Instead of doing that literally, I wanted to make it more like this.

if the argument provided is true, replace the whole if statement with the content provided for if it's true.

if it isn't true, just remove the whole thing altogether - unless there is an else statement. If there is, replace it with the content for else.

g1smd

8:12 pm on Dec 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



THere is no such parsing in HTML. The 'IF' stuff has to be done by JS in the browser or by PHP (or somesuch) on the server.

Unless you are on about this type of PHP parsing:

[b]<?php[/b]
IF ($expression)
[b]{[/b]
[b]?>[/b]
<strong>This is true.</strong>
[b]<?php[/b]
[b]}[/b]
ELSE
[b]{[/b]
[b]?>[/b]
<strong>This is false.</strong>
[b]<?php[/b]
[b]}[/b]
[b]?>[/b]

penders

12:42 pm on Dec 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Personally, I prefer the alternative syntax for control structures [uk2.php.net] if jumping in/out of PHP/HTML...

<?php if ($expression): ?> 
<strong>This is true.</strong>
<?php else: ?>
<strong>This is false.</strong>
<?php endif; ?>

This is really the same as g1smd's code, just an alternative syntax.

McBlack

6:01 pm on Dec 26, 2008 (gmt 0)

10+ Year Member



... you guys aren't getting what I'm saying. I know how PHP works, I'm just trying to make it so that I can use that in templates and for it to parse.