Chap 3 – PHP Quick Start COMP268-800RL Professor Mattos.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Objectives Using functions to organize PHP code
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
PHP Introduction.
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Chapter 4 Functions and Control Structures PHP Programming with MySQL.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 4- 1.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
JavaScript, Third Edition
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
Intro to PHP – Page 1 of 43CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: Intro to PHP Reading: Chapters 1.
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Class 2Intro to Databases Goals of this class Include & Require in PHP Generating Random Numbers in PHP Arrays – Numerically Indexed and Associative Program.
Making Decisions. 4.1 Relational Operators Used to compare numbers to determine relative order Operators: > Greater than < Less than >= Greater than.
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
Chapter 2 Functions and Control Structures PHP Programming with MySQL 2 nd Edition.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
CompSci 100E 2.1 Java Basics - Expressions  Literals  A literal is a constant value also called a self-defining term  Possibilities: o Object: null,
PHP Constructs Advance Database Management Systems Lab no.3.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
1 PHP Introduction Chapter 1. Syntax and language constructs.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions.
JavaScript, Fourth Edition
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Chapter Making Decisions 4. Relational Operators 4.1.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
Introduction to PHP and MySQL (Creating Database-Driven Websites)
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Chapter 4: Making Decisions.
Web Technologies PHP 5 Basic Language.
PHP (PHP: Hypertext Preprocessor)
Chapter 4: Making Decisions.
Expressions and Control Flow in JavaScript
PHP.
Basics.
PHP an introduction.
Problem 1 Given n, calculate 2n
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Chap 3 – PHP Quick Start COMP RL Professor Mattos

PHP Syntax and Constructs – The Tag opening tag ?> -> closing tag PHP script is placed between PHP open tag “ ”. The code between these two tags is what the PHP module processes. Covered in Chapter 2, Week 1

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 “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 Core: integer, float, string and boolean Special: null, array, object and resource. Covered in Chapter 4, Week 3

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 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 Defined with the define() function. They are global in scope. define(“PI”, );

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 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. NOTE;

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 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 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 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 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 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 Short form of the if/else syntax (condition) ? statement_if_true : statement_if_false

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 do-while -> checks looping expression at the end of the loop block. do { statements; } while (expression);

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 foreach -> iterate through an array. foreach($array_name as $value){ statements; } foreach($array_name as $name=>$value){ statements; }

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 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 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 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 supports pattern matching with regular expressions and regular expression metacharacters. Covered in Chapter 12, Week 11.