In PHP, tags are used to enclose PHP code within an HTML or XML document, allowing you to embed dynamic content and logic seamlessly into web pages. PHP tags are essential for differentiating PHP code from regular HTML content, making it possible to execute server-side scripts when a user requests a web page.


There are primarily two types of PHP tags:


  1. Short Tags (`<? ?>`):


   – Short tags are the most concise way to embed PHP code within your HTML. They consist of `<?` to start and `?>` to end, with the PHP code placed in between.


   – However, it’s important to note that short tags might not be enabled by default on all PHP installations, and their usage is discouraged in modern PHP development due to compatibility concerns.


  1. Standard Tags (`<?php ?>`):


   – Standard tags are the recommended and widely-accepted way to enclose PHP code. They start with `<?php` and end with `?>`. Any PHP code you want to execute goes within these tags.


   – Standard tags are more portable and ensure compatibility across different PHP setups.


For example, to display “Hello, World!” using PHP, you can use standard tags as follows:

<!DOCTYPE html>
    <title>PHP Tags Example</title>
    <p><?php echo "Hello, World!"; ?></p>


In this example, the PHP code within the `<?php ?>` tags dynamically generates the “Hello, World!” message within the HTML page when it is loaded in a web browser. PHP tags provide the foundation for creating dynamic and interactive web applications by allowing you to mix PHP logic seamlessly with your HTML content.

Previously at
Flag Argentina
time icon
Full Stack Engineer with extensive experience in PHP development. Over 11 years of experience working with PHP, creating innovative solutions for various web applications and platforms.