๐ŸŽ“ A1Learner
๐Ÿ”

PHP Syntax

PHP syntax is the set of rules for writing PHP code. One of these rules covers the case of keywords.

Keywords ignore case

A keyword is a word with a fixed job in PHP. ECHO is the echo keyword in capital letters, and it prints the line.

<?php
ECHO "Uppercase works\n";

A stranger mix of case

EcHo mixes capital and small letters. PHP still treats it as the echo keyword.

<?php
EcHo "Mixed case works\n";

Extra space changes nothing

This program spreads one statement across extra spaces and lines. It prints the same line as a tidy program.

<?php

echo    "Spaced out\n"
  ;

A missing semicolon

A parse error is an error PHP reports before a program runs. The first statement here has no semicolon, so PHP stops and prints its message.

<?php
echo "a"
echo "b";

Example

<?php
ECHO "First tidy line\n";
EcHo "Second tidy line\n";
eCHo "Third tidy line\n";

Key points

  • Syntax is the rule set that shapes each PHP statement.
  • Keywords ignore case in PHP.
  • Extra spaces and line breaks do not change the output.
  • Each statement ends with a semicolon.
  • A missing semicolon gives a parse error.

In this example, three echo statements use three cases of the keyword. Each statement ends with a semicolon. The lines print in order, one per statement.

Try it Yourself

Edit the code, then press Run.

Running is simulated ยท Programiz PHP Compiler

Exercise

What does PHP do when a statement misses its semicolon?