PHP Tutorial



PHP SYNTAX


๐Ÿงพ PHP Syntax

PHP scripts are written inside <?php ... ?> tags. These tags tell the server to interpret the enclosed code as PHP.

๐Ÿง  PHP is not case-sensitive for functions and keywords (like echo or IF), but variables are case-sensitive.

๐Ÿ”น Basic Structure

A simple PHP script looks like this:

<?php
  // This is a single-line comment
  echo "Hello PHP!";
?>
  

๐Ÿ“ Syntax Rules

  • PHP code must be enclosed in <?php ... ?>
  • Statements end with a semicolon ;
  • Comments:
    • // for single-line
    • /* ... */ for multi-line
  • PHP files usually have a .php extension

๐Ÿงช Example: Mixing HTML with PHP

<!DOCTYPE html>
<html>
<body>

  <h1>PHP Test</h1>

  <?php
    echo "This line is from PHP!";
  ?>

</body>
</html>
  

๐Ÿ”„ PHP Comments

<?php
  // This is a single-line comment

  # This is also a single-line comment

  /*
    This is a multi-line comment
    useful for longer notes.
  */
?>
  
โš ๏ธ Note: Always end PHP statements with a semicolon (;). Missing semicolons are a common beginner error!

๐Ÿ› ๏ธ Quick Tips

  • Use proper indentation to make your code readable.
  • Start with echo and print to output content.
  • Use comments to explain your logic, especially when learning.
โœ… Summary: PHP syntax is simple and clean. Begin every PHP script with <?php and use semicolons to end each command.

๐ŸŒŸ Enjoyed Learning with Us?

Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!

Leave a Google Review