tags:

views:

32

answers:

2

Hi,

here below explains how to embed PHP code in HTML files. Is there any name to referrer that way of writing PHP ?

http://onlamp.com/pub/a/php/2001/05/03/php_foundations.html

Javi

A: 

You just took it wrong. It is not PHP being embedded in HTML, but HTML being embedded in PHP.
To run PHP code a PHP interpreter is required. And usual browser doesn't have one.
Thus, you can add PHP code to HTML archive but it just won't work.

While embedding itself is called Escaping from HTML

Col. Shrapnel
+2  A: 

I assume you are referring to the syntax in that article that looks like this:

<?php if(conditions): ?>
... HTML CODE ...
<?php endif; ?>

That's called the Alternative Syntax for Control Structures. Unfortunately, that doesn't really roll off one's tongue very well.

The article also shows an example of the short open tag:

<?=$var?>
Bill Karwin
You should however avoid the usage of short open tags as it is considered bad practice. Use <?php .. code .. ?> instead.
Octavian Damiean
@MAINERROR: Yes, but do you know why short open tags are bad practice?
Bill Karwin
Because of the php ini. In some configs short_open_tag might not be turned on. At least thats the reason I knew.
Octavian Damiean
@MAINERROR: The short tags are also invalid XML, so if you use them, it's impossible to validate your page as XHTML.
Bill Karwin
+1 @Bill Karwin didn't know that thanks.
Octavian Damiean