SlideShare a Scribd company logo
Welcome to Computer
Programmer 2
PHP Language – Lesson 1 Prepared By:
Analyn G. Regaton
PHP Installation
1. Download and install sublime text – compiler
/editor
2. Download and install wamp server – to support
php file, database and also apache.
PHP SYNTAX (Basic)
A PHP script can be placed anywhere in the document.
A PHP script starts with <?php and ends with ?>:
The default file extension for PHP files is ".php".
A PHP file normally contains HTML tags, and some PHP
scripting code.
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:
Note: However; all variable names are case-
sensitive!
PHP Case Sensitivity
Look at the example in the left side; 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:
result
Comments in PHP
A comment in PHP code is a line that is not
executed as a part of the program. Its only
purpose is to be read by someone who is looking
at the code.
Comments can be used to:
•Let others understand your code
•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
Comments in PHP
PHP Variables
Variables are "containers" for storing
information.
Creating (Declaring) PHP
Variables
In PHP, a variable starts with the $ sign, followed
by the name of the variable:
After the execution of the statements in the
left, the variable $txt will hold the
value Hello world!, the variable $x will hold
the value 5, and the variable $y will hold the
value 10.5.
Note: When you assign a text value to a
variable, put quotes around the value.
Note: Unlike other programming languages,
PHP has no command for declaring a variable.
It is created the moment you first assign a
value to it.
PHP Variables
Rules for PHP variables:
•A variable starts with the $ sign, followed by the name of the variable
•A variable name must start with a letter or the underscore character
•A variable name cannot start with a number
•A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ )
•Variable names are case-sensitive ($age and $AGE are two different
variables)
PHP Variables
Output Variables
The PHP echo statement is often used to output data to the screen.
The following example will show how to output text and a variable:
result result
PHP Variables
PHP Variables Scope
In PHP, variables can be declared anywhere in
the script.
The scope of a variable is the part of the script
where the variable can be referenced/used.
PHP has three different variable scopes:
•local
•global
•static
Global and Local Scope
A variable declared outside a function has a GLOBAL
SCOPE and can only be accessed outside a function:
result
PHP Variables
A variable declared within a function has a LOCAL
SCOPE and can only be accessed within that function:
Global and Local Scope
result
PHP Variables
PHP The global Keyword
The global keyword is used to access a global variable from within a function.
To do this, use the global keyword before the variables (inside the function):
result
PHP Variables
PHP The static Keyword
Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes
we want a local variable NOT to be deleted. We need it for a further job.
To do this, use the static keyword when you first declare the variable:
result
PHP echo and print Statements
With PHP, there are two basic ways to get output: echo and print.
echo and print are more or less the same. They are both used to output data to the screen.
The differences are small: echo has no return value while print has a return value of 1 so it can be used in
expressions. echo can take multiple parameters (although such usage is rare) while print can take one
argument. echo is marginally faster than print.
The PHP echo Statement
The echo statement can be used with or without parentheses: echo or echo().
result
Display Text
PHP echo and print Statements
Display Variables
The following example shows how to output text and variables with the echo statement:
result
PHP echo and print Statements
The PHP print Statement
The print statement can be used with or without parentheses: print or print().
Display Text
The following example shows how to output text with the print command (notice that the text can
contain HTML markup):
PHP echo and print Statements
Display Variables
The following example shows how to output text and variables with the print statement:
The end !

More Related Content

PPTX
php basics
PDF
Introduction to HTML
PPT
Introduction to PHP.ppt
PPT
PHP complete reference with database concepts for beginners
PPT
Introduction to php
PPT
Control Structures In Php 2
PPTX
FYBSC IT Web Programming Unit IV PHP and MySQL
PPTX
L14 exception handling
php basics
Introduction to HTML
Introduction to PHP.ppt
PHP complete reference with database concepts for beginners
Introduction to php
Control Structures In Php 2
FYBSC IT Web Programming Unit IV PHP and MySQL
L14 exception handling

What's hot (20)

PDF
Php introduction
PDF
JavaScript - Chapter 8 - Objects
PDF
javascript objects
PDF
Python - variable types
PPTX
CSS- Cascading Style Sheet
PPT
PHP - Introduction to Object Oriented Programming with PHP
PPTX
Java script
PPT
What Is Php
 
PDF
Web Development Course: PHP lecture 1
PDF
Data Types In PHP
PDF
itft-Decision making and branching in java
PDF
Html forms
PPTX
Document Object Model
PPTX
Html images syntax
PDF
Introduction to php
PPTX
Design pattern (Abstract Factory & Singleton)
PPTX
PDF
Html,javascript & css
PPTX
Loops in java script
Php introduction
JavaScript - Chapter 8 - Objects
javascript objects
Python - variable types
CSS- Cascading Style Sheet
PHP - Introduction to Object Oriented Programming with PHP
Java script
What Is Php
 
Web Development Course: PHP lecture 1
Data Types In PHP
itft-Decision making and branching in java
Html forms
Document Object Model
Html images syntax
Introduction to php
Design pattern (Abstract Factory & Singleton)
Html,javascript & css
Loops in java script
Ad

Similar to Lesson 1 php syntax (20)

PPTX
Basic of PHP
PPTX
PHP BASICs Data Type ECHo and PRINT.pptx
PDF
PHP Basic & Variables
PDF
1336333055 php tutorial_from_beginner_to_master
PPTX
PHP2An introduction to Gnome.pptx.j.pptx
DOCX
PHP NOTES FOR BEGGINERS
PDF
Materi Dasar PHP
PDF
Programming in PHP Course Material BCA 6th Semester
PPTX
PHP Training Part1
PDF
Php tutorial from_beginner_to_master
PPTX
PPTX
Introduction to PHP (Hypertext Preprocessor).pptx
DOC
PHP MATERIAL
PPTX
3 Introduction to PHP Variables Moduless
PPTX
Php intro by sami kz
PPSX
PHP Comprehensive Overview
PDF
Php web development
DOCX
Free PHP Book Online | PHP Development in India
PPTX
Php by shivitomer
Basic of PHP
PHP BASICs Data Type ECHo and PRINT.pptx
PHP Basic & Variables
1336333055 php tutorial_from_beginner_to_master
PHP2An introduction to Gnome.pptx.j.pptx
PHP NOTES FOR BEGGINERS
Materi Dasar PHP
Programming in PHP Course Material BCA 6th Semester
PHP Training Part1
Php tutorial from_beginner_to_master
Introduction to PHP (Hypertext Preprocessor).pptx
PHP MATERIAL
3 Introduction to PHP Variables Moduless
Php intro by sami kz
PHP Comprehensive Overview
Php web development
Free PHP Book Online | PHP Development in India
Php by shivitomer
Ad

More from MLG College of Learning, Inc (20)

PPTX
PPTX
PC111-lesson1.pptx
PPTX
PC LEESOON 6.pptx
PPTX
PC 106 PPT-09.pptx
PPTX
PPTX
PPTX
PPTX
PC 106 Slide no.02
PPTX
PPTX
PPTX
PC 106 Slide 1.pptx
PDF
Db2 characteristics of db ms
PDF

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Cell Structure & Organelles in detailed.
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Lesson notes of climatology university.
PDF
Trump Administration's workforce development strategy
PDF
Anesthesia in Laparoscopic Surgery in India
Computing-Curriculum for Schools in Ghana
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Module 4: Burden of Disease Tutorial Slides S2 2025
Orientation - ARALprogram of Deped to the Parents.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
GDM (1) (1).pptx small presentation for students
Supply Chain Operations Speaking Notes -ICLT Program
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Cell Types and Its function , kingdom of life
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Cell Structure & Organelles in detailed.
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Lesson notes of climatology university.
Trump Administration's workforce development strategy
Anesthesia in Laparoscopic Surgery in India

Lesson 1 php syntax

  • 1. Welcome to Computer Programmer 2 PHP Language – Lesson 1 Prepared By: Analyn G. Regaton
  • 2. PHP Installation 1. Download and install sublime text – compiler /editor 2. Download and install wamp server – to support php file, database and also apache.
  • 3. PHP SYNTAX (Basic) A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends with ?>: The default file extension for PHP files is ".php". A PHP file normally contains HTML tags, and some PHP scripting code. Note: PHP statements end with a semicolon (;).
  • 4. 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: Note: However; all variable names are case- sensitive!
  • 5. PHP Case Sensitivity Look at the example in the left side; 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: result
  • 6. Comments in PHP A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to be read by someone who is looking at the code. Comments can be used to: •Let others understand your code •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
  • 8. PHP Variables Variables are "containers" for storing information. Creating (Declaring) PHP Variables In PHP, a variable starts with the $ sign, followed by the name of the variable: After the execution of the statements in the left, the variable $txt will hold the value Hello world!, the variable $x will hold the value 5, and the variable $y will hold the value 10.5. Note: When you assign a text value to a variable, put quotes around the value. Note: Unlike other programming languages, PHP has no command for declaring a variable. It is created the moment you first assign a value to it.
  • 9. PHP Variables Rules for PHP variables: •A variable starts with the $ sign, followed by the name of the variable •A variable name must start with a letter or the underscore character •A variable name cannot start with a number •A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) •Variable names are case-sensitive ($age and $AGE are two different variables)
  • 10. PHP Variables Output Variables The PHP echo statement is often used to output data to the screen. The following example will show how to output text and a variable: result result
  • 11. PHP Variables PHP Variables Scope In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: •local •global •static Global and Local Scope A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function: result
  • 12. PHP Variables A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function: Global and Local Scope result
  • 13. PHP Variables PHP The global Keyword The global keyword is used to access a global variable from within a function. To do this, use the global keyword before the variables (inside the function): result
  • 14. PHP Variables PHP The static Keyword Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. To do this, use the static keyword when you first declare the variable: result
  • 15. PHP echo and print Statements With PHP, there are two basic ways to get output: echo and print. echo and print are more or less the same. They are both used to output data to the screen. The differences are small: echo has no return value while print has a return value of 1 so it can be used in expressions. echo can take multiple parameters (although such usage is rare) while print can take one argument. echo is marginally faster than print. The PHP echo Statement The echo statement can be used with or without parentheses: echo or echo(). result Display Text
  • 16. PHP echo and print Statements Display Variables The following example shows how to output text and variables with the echo statement: result
  • 17. PHP echo and print Statements The PHP print Statement The print statement can be used with or without parentheses: print or print(). Display Text The following example shows how to output text with the print command (notice that the text can contain HTML markup):
  • 18. PHP echo and print Statements Display Variables The following example shows how to output text and variables with the print statement: