PHP Syntax

Tags, statements and case sensitivity.

✍️ 2 exercises in this lesson

PHP code is written between <?php and ?>. In files that contain only PHP, leave out the closing ?>.

  • Every statement ends with a semicolon ;.
  • Keywords (echo, if, function) are not case-sensitive.
  • Variable names are case-sensitive: $name and $Name are different.
  • echo and print output text.

PHP Comments

// single line, # single line, /* multi-line */

Key Takeaways: PHP Syntax

Mastering PHP Syntax helps you write clean and reliable PHP code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

PHP Syntax Code Example

PHP
<?php
// A single-line comment
$color = "teal";
echo "My car is " . $color . "<br>";
ECHO "Keywords are case-insensitive<br>";
print "print also works";
Output
My car is teal
Keywords are case-insensitive
print also works
Run this example on your own computer. The "Get Started" lesson shows how to set it up.

PHP Syntax Practice Exercises

Check what you learned in “PHP Syntax”.

/ 2 solved
Fill in the blank

Output text with PHP.

<?php  "Welcome!"; ?>
✓ Correct! Not quite. Try again.
Multiple choice

Which part of PHP is case-sensitive?

✓ Correct! Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services