Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If else embedding inside html

Tags:

html

php

What is the correct way of embedding if else and elseif conditions inside html?

like image 556
user550265 Avatar asked Jan 19 '11 04:01

user550265


People also ask

How do you write if else in HTML?

php endif; ?> Elseif fires whether $first_condition is true or false, as do additional elseif statements, if there are multiple.

Can HTML be embedded inside PHP if statement?

Yes, HTML can be embedded inside an 'if' statement with the help of PHP.

How can I write HTML code inside PHP?

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the PHP. Step 2: Now, we have to place the cursor in any tag of the <body> tag where we want to add the code of PHP. And, then we have to type the start and end tag of PHP.

What is nested IF ELSE statement in PHP?

The nested if statement contains the if block inside another if block. The inner if statement executes only when specified condition in outer if statement is true.


1 Answers

I recommend the following syntax for readability.

<? if ($condition): ?>   <p>Content</p> <? elseif ($other_condition): ?>   <p>Other Content</p> <? else: ?>   <p>Default Content</p> <? endif; ?> 

Note, omitting php on the open tags does require that short_open_tags is enabled in your configuration, which is the default. The relevant curly-brace-free conditional syntax is always enabled and can be used regardless of this directive.

like image 197
coreyward Avatar answered Oct 22 '22 02:10

coreyward