chap 3 php quick start n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Chap 3 – PHP Quick Start PowerPoint Presentation
Download Presentation
Chap 3 – PHP Quick Start

Loading in 2 Seconds...

play fullscreen
1 / 26

Chap 3 – PHP Quick Start - PowerPoint PPT Presentation


  • 83 Views
  • Uploaded on

Chap 3 – PHP Quick Start. COMP268-800RL Professor Mattos. PHP Syntax and Constructs – The Tag. <?php -> opening tag ?> -> closing tag PHP script is placed between PHP open tag “<?php” and PHP close tag “?>”. The code between these two tags is what the PHP module processes.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Chap 3 – PHP Quick Start' - landry


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chap 3 php quick start

Chap 3 – PHP Quick Start

COMP268-800RL

Professor Mattos

php syntax and constructs the tag
PHP Syntax and Constructs – The Tag
  • <?php -> opening tag
  • ?> -> closing tag
  • PHP script is placed between PHP open tag “<?php” and PHP close tag “?>”.
  • The code between these two tags is what the PHP module processes.
  • Covered in Chapter 2, Week 1
php syntax and constructs comments
PHP Syntax and Constructs – Comments
  • There are three styles of comments:
    • C -> /* This is a C style comment. */
    • C++ -> // This is a C++ style comment.
    • Shell -> # This is a shell style comment.
  • Covered in Chapter 2, Week 1
php syntax and constructs printing output
PHP Syntax and Constructs – Printing Output
  • “print” displays a string and returns an integer value.
  • “echo” prints comma-separated strings and does not return anything.
  • You also have printf(), sprintf() and fprintf(). Covered in Chapter 6, Week 5
php syntax and constructs data types
PHP Syntax and Constructs – Data Types
  • Core: integer, float, string and boolean
  • Special: null, array, object and resource.
  • Covered in Chapter 4, Week 3
php syntax and constructs variables
PHP Syntax and Constructs – Variables
  • Start with a “$” sign, followed by a letter and any number of alphanumeric characters, including underscore.
  • $first_name = “Roberto”
  • $last_name = “Mattos”
  • echo $first_name, “ “, $last_name;
php syntax and constructs predefined variables
PHP Syntax and Constructs – Predefined Variables
  • Also called “superglobals”, as they are available anywhere in the script.

$_GLOBALS $_FILES

$_ENV $_GET

$_POST $_SESSION

$_COOKIE $_REQUEST

$_SERVER

php syntax and constructs constants
PHP Syntax and Constructs – Constants
  • Defined with the define() function.
  • They are global in scope.
  • define(“PI”, 3.141592);
php syntax and constructs numbers
PHP Syntax and Constructs – Numbers
  • PHP supports integers as well as floating-point, scientific notation, booleans and null.
  • $year = 2013;
  • $price = 29.95;
  • $color = 0x33CC99;
  • $distance_to_moon = 3.844e+5;
php syntax and constructs strings and quotes
PHP Syntax and Constructs – Strings and quotes
  • Sequence of characters enclosed in quotes.
  • Quotes must match-> “string” or ‘string’
  • Variables and backslash sequences are interpreted within double quotes.
  • here-doc -> block of text embedded between user-defined tags, first preceded by <<<. Entire block is treated as surrounded by double quotes.

print <<<NOTE

It is raining. <br>

NOTE;

php syntax and constructs boolean values
PHP Syntax and Constructs – Boolean Values
  • Exactly one bit with two possible values:
    • 0 or 1
    • True or False
    • Off or On
php syntax and constructs null
PHP Syntax and Constructs – Null
  • Null means no value assigned (not a blank space, not an empty string, not a zero).
  • unset() function assigns Null to a variable.
    • unset($var); // now $var is Null
php syntax and constructs operators
PHP Syntax and Constructs – Operators
  • Assignment: =, +=, -=, *=, %=, ^=, &=, |=, .=
  • Equality: ==, !=
  • Identical: ===, !===
  • Relational: >, >=, <, <=
  • Logical: &&, ||, !
  • Auto increment/auto decrement: ++, --
  • Bitwise: ~, &, |, ^, <<, >>
  • String Concatenation: .
  • Arithmetic: *, /, -, +, %
  • Casting: (int), (float), (string), (bool), (array), (object)
php syntax and constructs arrays
PHP Syntax and Constructs – Arrays
  • Indexed collection of data.
  • PHP supports traditional and associative arrays.
    • Traditional-> indexed by integers starting at 0.
    • Associative-> indexed by strings.
  • Covered on Chapter 8, Week 7
php syntax and constructs conditionals 1 2
PHP Syntax and Constructs – Conditionals 1/2
  • if, if/else, if/elseif -> If expression is evaluated to true, block following the expression is executed.

if (expression) {

statements;

}

elseif (expression){

statements;

}

else {

statements;

}

php syntax and constructs conditionals 2 2
PHP Syntax and Constructs – Conditionals 2/2
  • Switch -> expression is evaluated and matched against a series of case values until one matches.

switch ($variable_name) {

case valueA:

{statements;}

break;

case valueB:

{statements;}

break;

default:

{statements;}

}

php syntax and constructs conditional operator
PHP Syntax and Constructs – Conditional Operator
  • Short form of the if/else syntax

(condition) ? statement_if_true : statement_if_false

php syntax and constructs loops 1 4
PHP Syntax and Constructs – Loops 1/4
  • while -> as long as the expression tests true, the loop continues to iterate.

while (conditional expression) {

statements;

}

php syntax and constructs loops 2 4
PHP Syntax and Constructs – Loops 2/4
  • do-while -> checks looping expression at the end of the loop block.

do {

statements;

} while (expression);

php syntax and constructs loops 3 4
PHP Syntax and Constructs – Loops 3/4
  • for -> has three expressions to evaluate, separated by semicolon. First initializes a variable. Second tests whether the value is true, and if so, the block of statements is executed. After execution of the block, third expression is executed, changing value to be tested again.

for (initialization; conditional expression; increment/decrement){

statements;

}

php syntax and constructs loops 4 4
PHP Syntax and Constructs – Loops 4/4
  • foreach -> iterate through an array.

foreach($array_name as $value){

statements;

}

foreach($array_name as $name=>$value){

statements;

}

php syntax and constructs loop control
PHP Syntax and Constructs – Loop control
  • “break” statement -> break out of a loop from within the loop block.
  • “continue” statement -> skip over the remaining statements within the loop and start back at the top of the loop for a new iteration
php syntax and constructs functions
PHP Syntax and Constructs – Functions
  • Functions -> block of code that performs a task and can be invoked from another part of the program.

function function_name (argument1, argument2, argument3, …){

statements;

}

  • Covered on Chapter 9, week 8
php syntax and constructs classes and objects
PHP Syntax and Constructs – Classes and Objects
  • PHP support objects.
  • Class is a collection of variables and functions, called properties and methods.
  • Objects are created with the “new” operator.
  • $this is a special pseudo-variable that references the current object.
  • PHP supports inheritance.
php syntax and constructs files
PHP Syntax and Constructs – Files
  • PHP comes with a set of built-in functions to work with files.

require -> replaced by contents of file.

require_once -> replaced with contents of file.

include -> same as require, but happens only during program execution.

include_once -> same as require_once, but happens only during program execution.

  • To open a file, filename must be assigned to a filehandle.
  • Covered on Chapter 11, week 10.
php syntax and constructs regular expressions
PHP Syntax and Constructs – Regular Expressions
  • PHP supports pattern matching with regular expressions and regular expression metacharacters.
  • Covered in Chapter 12, Week 11.