Theoretical Paper
- Computer Organization
- Data Structure
- Digital Electronics
- Object Oriented Programming
- Discrete Mathematics
- Graph Theory
- Operating Systems
- Software Engineering
- Computer Graphics
- Database Management System
- Operation Research
- Computer Networking
- Image Processing
- Internet Technologies
- Micro Processor
- E-Commerce & ERP
Practical Paper
Industrial Training
PHP Syntax
A PHP script is executed on the server, and the plain HTML result is sent back to the browser.
Basic PHP Syntax
A PHP script can be placed anywhere in the document.
A PHP script starts with < ?php and ends with ?>:
< ?php // PHP code goes here ?>
The default file extension for PHP files is ".php".
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
< !DOCTYPE class="attributecolor" style="color:red"> html="tagcolor" style="color:mediumblue">> < html class="tagcolor" style="color:mediumblue">> < body class="tagcolor" style="color:mediumblue">> < h1 class="tagcolor" style="color:mediumblue">>My first PHP page< /h1 class="tagcolor" style="color:mediumblue">> < ?php class="phpnumbercolor" style="color:red"> class="phpkeywordcolor" style="color:mediumblue"> echo class="phpstringcolor" style="color:brown">"Hello World!"; class="phptagcolor" style="color:red">?> < /body class="tagcolor" style="color:mediumblue">> < /html class="tagcolor" style="color:mediumblue">>
Note: PHP statements end with a semicolon (;).
PHP Case Sensitivity
In PHP, keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive.
In the example below, all three echo statements below are equal and legal:
Example
< !DOCTYPE class="attributecolor" style="color:red"> html="tagcolor" style="color:mediumblue">> < html class="tagcolor" style="color:mediumblue">> < body class="tagcolor" style="color:mediumblue">> < ?php class="phpnumbercolor" style="color:red"> class="phpkeywordcolor" style="color:mediumblue"> ECHO class="phpstringcolor" style="color:brown">"Hello World!< br>"; class="phpkeywordcolor" style="color:mediumblue">echo class="phpstringcolor" style="color:brown"> "Hello World!< br>"; class="phpnumbercolor" style="color:red"> class="phpkeywordcolor" style="color:mediumblue"> EcHo class="phpstringcolor" style="color:brown">"Hello World!< br>"; class="phptagcolor" style="color:red">?> < /body class="tagcolor" style="color:mediumblue">> < /html class="tagcolor" style="color:mediumblue">>
Look at 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
< !DOCTYPE class="attributecolor" style="color:red"> html="tagcolor" style="color:mediumblue">> < html class="tagcolor" style="color:mediumblue">> < body class="tagcolor" style="color:mediumblue">> < ?php $color = class="phpstringcolor" style="color:brown">"red"; class="phpnumbercolor" style="color:red"> class="phpkeywordcolor" style="color:mediumblue"> echo class="phpstringcolor" style="color:brown">"My car is " . $color . class="phpstringcolor" style="color:brown">"< br>"; class="phpkeywordcolor" style="color:mediumblue"> echo class="phpstringcolor" style="color:brown">"My house is " . $COLOR . class="phpstringcolor" style="color:brown">"< br>"; class="phpkeywordcolor" style="color:mediumblue">echo class="phpstringcolor" style="color:brown"> "My boat is " . $coLOR . class="phpstringcolor" style="color:brown">"< br>"; class="phptagcolor" style="color:red">?> < /body class="tagcolor" style="color:mediumblue">> < /html class="tagcolor" style="color:mediumblue">>