Php tags | Tags used for PHP

Php is a server side language. It runs on a server. But how we can use the PHP code in our pages is a question for a PHP learner. If you want to run PHP on your local machine you have to install XAMP server package, MAMP server or WAMP server on your local machine. We have told you in previous two post that how to install XAMP and how to install WAMP on your local machine. These packages help us make our machine a server and run the PHP script on it.

The PHP code only runs in a file with .php extension. You can add HTML code in a PHP file but the PHP code will not run in any other extension. To put a PHP code into your pages you have to use the PHP tags. The code inside the PHP tags will be treated as PHP code. There are a few kinds of PHP tags. The followings are the examples of PHP tags list:

PHP Tags List:

Standard PHP tags:

<?php               ?>

PHP Short Tags List:

(considered not good)

<?                       ?>

<?=                     ?>

Asp Style tags in PHP:

(considered very bad)

<%                      %>

<%=                    %>

The above tags are the tags which can be used while writing PHP code. The recommended are the standard tags why because you don’t have to change the php.ini file to use these tags. If you are not using the standard tags then you have to change the php.ini file to use them.

PHP Short tags are the second choice to use for PHP code. But it is considered bad because if you have a code with short tags and you are pasting it on a server that is not supporting yet the short tags the code will not work.

Using ASP style tags in PHP is considered very bad. It is because of the problem I have just explained to you in the paragraph above.

Here is a PHP code example:

<html>

<head>

<title>PHP tags example</title>

</head>

<body>

<?php  phpinfo(); ?>

</body>

</html>

In the above example we are just writing one line of code. The code starts with the “<?php” tag that tells the server to now it is the start of the PHP code. The “?>” tag or ending PHP tag tells the code parser that it is the end of the PHP code. The result of the above code will be the information about the PHP running on your server.

Comments