Learn PHP tags

PHP scripts are different from the HTML scripts by using delimiting characters that tell the server to execute the PHP application to interpret that which is contained in the code. There are four ways to write PHP tags.

Default Syntax

The default is starting the PHP script with <?php and closing out the script with ?>.

Following example demonstrates how this would look within HTML code:

	
	<html>
	<head>
	<title>Default Syntax</title>
	</head>
	<body>
	
	<h3>PHP Default Syntax</h3>
	<?php
		echo "This is an example of using PHP Default Syntax";
		
		or
		
		print "This is an example of using PHP Default Syntax";
	?>
	
	</body>
	</html>
	

Script Syntax

Due to limitations with certain HTML editors, PHP added the ability to support a mainstream delimiter variant, <script>.

Following example demonstrates how this would look within HTML code:

	
	<script language="php">
		echo "This is an example of using PHP script delimiting syntax";
		
		or
		
		print "This is an example of using PHP script delimiting syntax";
	?>
	
	</script>
	

Short Tag

Due to the fact that many programmers are interested in minimizing the amount of code that needs to be written to accomplish a task. PHP implemented a shorter delimiter syntax to support this desire. Instead of needing to type <?php to start the PHP script, programmers can simply type <? to start the PHP script.

Following example demonstrates how this would look within HTML code:

	
	<?
		echo "This is an example of using PHP Short Tag Syntax";
		
		or
		
		print "This is an example of using PHP Short Tag Syntax";
	?>
	

ASP-Style

There are many PHP programmers that have experience with other similar programming language, such as ASP. ASP delimits code using <% and %>. PHP has provided support for this type of delimiting.

Following example demonstrates how this would look within HTML code:

	
	<%
		echo "This is an example of using ASP-Style delimiting syntax";
		
		or
		
		print "This is an example of using ASP-Style delimiting syntax";
	%>
	

Do you want Youtube channel of Campuslife

Please provide your suggestion on feedback page.

Subscribe Now

Post Your Comment