Introduction to PHP PHP PHP started out as

  • Slides: 27
Download presentation
Introduction to PHP

Introduction to PHP

PHP? PHP started out as a small open source project that evolved as more

PHP? PHP started out as a small open source project that evolved as more and more people found out how useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994. PHP: PHP Hypertext Preprocessor Syntax is C-Like Server side scripting language that is embedded in HTML PHP supports a large number of major protocols

Characteristics of PHP Simplicity Efficiency Security Flexibility Familiarity

Characteristics of PHP Simplicity Efficiency Security Flexibility Familiarity

Popularity of PHP The PYPL Popularit. Y of Programming Language Index is created by

Popularity of PHP The PYPL Popularit. Y of Programming Language Index is created by analyzing how often language tutorials are searched on Google.

PHP Market Share

PHP Market Share

Usage of Server-side programming languages for websites

Usage of Server-side programming languages for websites

Escaping in PHP Canonical PHP tags: Short-open (SGML-style) tags: <? . . . ?

Escaping in PHP Canonical PHP tags: Short-open (SGML-style) tags: <? . . . ? > Set the short_open_tag setting in your php. ini file to on. This option must be disabled to parse XML with PHP because the same syntax is used for XML tags. ASP-style tags <? php. . . ? > <%. . . %> HTML script tags: <script language="PHP">. . . </script>

Exercise Create your first PHP script. Write the string “Hello world. . is it

Exercise Create your first PHP script. Write the string “Hello world. . is it me you’re looking for? ”

Commenting PHP code Single-line comments #This is a comment //This is a comment Multi-lines

Commenting PHP code Single-line comments #This is a comment //This is a comment Multi-lines /* comments This is a comment for multiple lines */

Things to Remember PHP is whitespace insensitive PHP is case sensitive Statements are expressions

Things to Remember PHP is whitespace insensitive PHP is case sensitive Statements are expressions terminated by semicolons Expressions are combinations of tokens Braces make blocks

Variables All variables in PHP are denoted with a leading dollar sign ($). The

Variables All variables in PHP are denoted with a leading dollar sign ($). The value of a variable is the value of its most recent assignment. Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right. Variables can, but do not need, to be declared before assignment. Variables in PHP do not have intrinsic types - a variable does not know in advance whether it will be used to store a number or a string of characters. Variables used before they are assigned have default values. PHP does a good job of automatically converting types from one to another when necessary. PHP variables are Perl-like.

PHP Data Types Integer Doubles Booleans NULL String Array Object Resources Simple Types Compound

PHP Data Types Integer Doubles Booleans NULL String Array Object Resources Simple Types Compound Types Special variables that reference to external resources

Variable Scopes Local variables – variable declared in a function, and can only be

Variable Scopes Local variables – variable declared in a function, and can only be referenced in that function.

Variable Scopes Function parameters - are declared after the function name and inside parentheses.

Variable Scopes Function parameters - are declared after the function name and inside parentheses.

Variable Scopes Global variables – can be accessed in any part of the program.

Variable Scopes Global variables – can be accessed in any part of the program. Must be declared using the keyword GLOBAL

Variable Scopes Static variables – does not lose the value when the function exits

Variable Scopes Static variables – does not lose the value when the function exits and will still hold the value when it is called again. Uses the keyword STATIC

Variable naming Variable names must begin with a letter or underscore character. A variable

Variable naming Variable names must begin with a letter or underscore character. A variable name can consist of numbers, letters, underscores but you cannot use characters like + , - , % , ( , ). & , etc There is no size limit for variables.

Operator types Arithmetic Operators

Operator types Arithmetic Operators

Operator types Comparison Operators

Operator types Comparison Operators

Operator types Logical Operators

Operator types Logical Operators

Operator types Assignment Operators

Operator types Assignment Operators

Operator types Conditional Operators

Operator types Conditional Operators

Precedence of PHP Operators

Precedence of PHP Operators

If…else statement

If…else statement

Else. If statement

Else. If statement

Switch statement

Switch statement

Exercise 1. Create a variable named count and assign the number 0 2. Create

Exercise 1. Create a variable named count and assign the number 0 2. Create a