Forside > PHP > PHP Tag styles

PHP: Tag styles

By Kristoffer Bohmann

While PHP lets you output tags in a variety of ways, the default tag style is recommended.

You can output PHP tags in five basic ways.

1) Default tag style (recommended)

The default tag style is recommended because it will work in all PHP installations. Examples:

<?php echo "Hello World"; ?>

<?php echo "You can split strings across
many lines."; ?>

2) Short tag style

<? echo "Hello world"; ?>

Notice: This tag will fail if short_open_tag is set to Off in php.ini.

3) Alias (for the Short tag style)

<?="Hello world"; ?>

Notice: This tag will fail if short_open_tag is set to Off in php.ini.

4) Long Tag style (rarely used)

The long tag style is cumbersome and rarely used. It was created for Editors such as Microsoft FrontPage that did not like <??>-symbols. Example:

<script language="php">
echo "Hello world";
</script>

5) ASP Tag style (rarely used)

Tags as in ASP Classic. This will only work when asp_tags are set to On in php.ini.

<%= "Hello world"; %>

<% echo "Hello world"; %>