PHP 5 Syntax

When you start working with a new language, like PHP, chances are that you will make lots of syntax errors. A syntax error is a missed semicolon, an unclosed parenthesis and so on. To detect these errors, you will usually have to call up your page in a browser,PHP script is executed on the server, and the plain HTML result is sent back to the browser.A PHP file normally contains HTML tags, and some PHP scripting code.Below, we have an example of a simple PHP file, with a PHP script that uses a built-in PHP function "echo" to output the text "Hello World!" on a web page:

Example -

Comments in PHP

A comment in PHP code is a line that is not read/executed as part of the program. Its only purpose is to be read by someone who is editing the code!

  • To let others understand what you are doing - Comments let other programmers understand what you were doing in each step (if you work in a group)
  • Remind yourself of what you did - Most programmers have experienced coming back to their own work a year or two later and having to re-figure out what they did. Comments can remind you of what you were thinking when you wrote the code
  • Example -

    PHP Case Sensitivity

    In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are NOT case-sensitive.

    In the example below, all three echo statements below are legal (and equal):

    Example -

    In the example below, only the first statement will display the value of the $color variable (this is because $color, $COLOR, and $coLOR are treated as three different variables):

    Example -