If you want to use control structures in P HP.
Like if for.
And so on when mixing p.h. P and h.t. email then there's an alternative syntax you need to use this
alternative syntax is basically to change the opening brace to a colon then replace the closing brace
with END IF end far and so on.
This way you can have h.t. male code inside a p p control structure like this.
Let's look at an example.
Earlier on in the course we learnt how to use the if else if else control structure in HP and we wrote
this code to display a message based on the hour of the day.
Let's convert this to a mix of P HP and it's dml.
First we'll cut out this code.
We'll insert some basic s t email and we'll paste the p p code here inside the H T mail.
If we add a p-h P closing tag at the end like that then this code will work without any further changes.
When we view it in a browser and here's the message coming from the p-h P code.
But as we just learnt it's not ideal to be echoing out strings like this inside h.t. AML.
So let's change it so that we keep the p p control structure and the AITs tier male content separate.
First let's move where we're setting this variable up to the top.
It's quite common to move any code that is just setting our retrieving data up to the top like this
before the term owl so that the p s p mixed in with the h t email is kept to a minimum and therefore
the cold is clearer and easier to understand.
Then in our IF statement let's change the opening.
Curly brace to a colon.
And then add a p-h P closing tag.
Then we can get rid of the Echo and the quotes because we're now in turmoil here.
Again far the semicolon and the quotes at the end and we'll just move this up so it's on the same line
making sure we leave a space before the p p opening tag and the if statement.
Now that we're in HS t email here to go back to p p code.
We need another p p opening tack
and then at the end we'll change the curly brace to akol on and close the p p again like that and we
can get rid of the echo.
And the quote and the quote and the semicolon.
And we can continue like that all the way down the rest of the if statement and then at the end instead
of this final closing brace we put end if like that.
Now in the browser we get the same result.
However now our p h p code which is the dynamic part of the page is separate from its female content
which is static.
So instead of some simple text in here we could have several h.t. Amount elements for example but written
in H term L rather than a string in P H P.
The same alternative syntax is useful while loops followups and so on only ending in end while end far
end for each and so on.