PHP
📝 What Is Syntax in PHP (Writing Rules)?
In programming, syntax represents the structural rules that dictate how code must be written for the compiler or interpreter to parse it correctly. PHP syntax is clean, flexible, and heavily inspired by C-style languages, making it exceptionally easy to learn.
1️⃣ PHP Code Open and Close Tags
Unlike static HTML markup, PHP code cannot be written freely in a document. The PHP parser needs dedicated tags to distinguish backend code from standard text or HTML markup.
2️⃣ Four Methods of Declaring PHP Tags
🔹 1. Standard & Best Practice Usage ✅
This is the standard, safest, and most portable method across all hosting environments. It is fully supported by every PHP version and web server.
<?php
echo "Extra Eğitim - Volkan Alakent";
?>
🔹 2. Short Open Tags ⚠ (Not Recommended)
Shorthand syntax (<? ... ?>) or print shorthands (<?= ... ?>) allow writing shorter code blocks:
<?php
echo "Teachwebcode.com";
?>
<?= "Extra Eğitim - Volkan Alakent" ?>
- Warning: Short tags rely on server settings. If short_open_tag is disabled in the server configuration, code using this format will fail to execute or print raw PHP text to screen.
🔹 3. ASP-Style Tags (Deprecated / Obsolete)
Historically copied from Active Server Pages (ASP), using <% ... %> tags is completely removed from modern PHP environments.
<%
echo "Extra Eğitim - Volkan Alakent";
%>
🔹 4. Script Tag Style (Obsolete)
An outdated, legacy format that embedding PHP within HTML script tags is no longer supported in modern PHP releases.
<script language="php">
echo "Extra Eğitim - Volkan Alakent";
</script>
3️⃣ Server Configuration (php.ini) Requirements
For non-standard opening tags to function, specific server directive settings in the core php.ini configuration file must be enabled:
- For short tags:
short_open_tag = On - For ASP tags:
asp_tags = On
-
Best Practice Note: Always stick strictly to standard
<?php ... ?>tags to guarantee project portability across any web server configuration.
4️⃣ Semicolon Terminating Rule (;)
In PHP, every discrete instruction statement **must** end with a semicolon (;). The semicolon instructs the PHP interpreter that the current command has completed execution.
<?php
echo "Extra Eğitim - Volkan Alakent";
echo "A’dan Z’ye PHP Görsel Eğitim Seti";
?>
- Forgetting a trailing semicolon triggers a fatal **Parse Error / Syntax Error** that halts code execution.
-
📝 Brief Summary
- PHP code must be contained inside designated PHP opening and closing tags.
-
Always use standard
<?php ... ?>tags to ensure portability and security. -
Every standalone PHP code line must terminate with a semicolon (
;).
