1.2. Introduction To PHP & Lexical Structure
1.2. Introduction To PHP & Lexical Structure
1
Topics Covered
▪ Server Side Programming
▪ What is PHP, Why PHP
▪ Lexical Structure
▪ Case Sensitivity
▪ Statements
▪ PHP comments
▪ PHP white space
▪ Semicolon
▪ PHP variables
▪ Constants
▪ PHP literal
2
Server-Side web programming
• Server-side pages are programs written using one of
many web programming languages/frameworks
– examples: PHP, Java/JSP, Ruby on Rails, ASP.NET, Python, Perl
• Web server:
– contains software that allows it to run server side programs
– sends back their output as responses to web requests
– we use PHP
What is PHP?
Free and
open
source
Co
m
mp le ibl pat
S i e
• PHP files can contain text, HTML,
CSS, JavaScript, and PHP code
What is • PHP code is executed on the server,
PHP files ? and the result is returned to the
browser as plain HTML
• PHP files have extension “.php”
Set Up PHP on Your Own PC
?>
PHP
<?php
echo "Hello, world!";
?>
PHP
Hello world!
output
PHP Case Sensitivity
• In PHP, NO keywords (e.g. If, else, while, echo), classes,
functions, and user-defined functions are case-sensitive.
• Note: However; all variable names are case-sensitive!
<?php
ECHO "Hello World!<br>";
echo "Hello World!<br>";
EcHo "Hello World!<br>";
?>
PHP
<?php
$color = "red";
echo "My car is " . $color . "<br>";
echo "My house is " . $COLOR . "<br>";
echo "My boat is " . $coLOR . "<br>";
?>
PHP
PHP syntax template
HTML content
<?php
PHP code
?>
HTML content
<?php
PHP code
?>
HTML content ... PHP
print "text";
echo "text";
PHP
Console output: print/echo
PHP
Hello world! Escape "chars" are the SAME as in Java! You can have line
breaks in a string. A string can use "single-quotes". It's cool!
output
Comments
# single-line comment
// single-line comment
/*
multi-line comment
*/
PHP
like Java, but # is also allowed
a lot of PHP code uses # comments instead
of //
Summary
▪ Server Side Programming
▪ What is PHP, Why PHP
▪ Lexical Structure
▪ Case Sensitivity
▪ Statements
▪ PHP comments
▪ PHP white space
▪ Semicolon
▪ PHP variables
▪ Constants
▪ PHP literal
References
1. Steven Holzner, “PHP:The Complete
Reference”, McGraw Hill Education, 2017
2. https://www.w3schools.com/php/
3. https://www.tutorialspoint.com/php/index.htm
33