PHP Tags: <?php ?>
All PHP code must be written inside special tags so that the server knows to interpret it as PHP.
🔸 Standard PHP Opening and Closing Tag:
<?php
// Your PHP code goes here
?>
This is the most commonly used and recommended syntax for writing PHP code.
🔸 Example:
<?php
echo "Welcome to PHP!";
?>
🔸 Alternative Syntaxes:
- Short open tag:
<? echo "Hi"; ?>(Not recommended — must be enabled inphp.ini) - ASP-style tags:
<% %>(Deprecated and no longer supported) - Script tag (for embedding in HTML):
<html>
<body>
<h1><?php echo "Hello from PHP!"; ?></h1>
</body>
</html>
<?php ?> tags for maximum compatibility across servers.


