PHP 1. Introduction Temasek Polytechnic

Similar documents
What is PHP? [1] Figure 1 [1]

PHP: The Basics CISC 282. October 18, Approach Thus Far

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

INTERNET PROGRAMMING. Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology

Let's Look Back. We talked about how to create a form in HTML. Forms are one way to interact with users

Lecture 12. PHP. cp476 PHP

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

PHP by Pearson Education, Inc. All Rights Reserved.

PHP 5 Introduction. What You Should Already Know. What is PHP? What is a PHP File? What Can PHP Do? Why PHP?

Web Scripting using PHP

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

Web Scripting using PHP

PHP. Interactive Web Systems

CSCB20 Week 8. Introduction to Database and Web Application Programming. Anna Bretscher* Winter 2017

Introduction to Bioinformatics

Web Engineering (Lecture 08) WAMP

Internet & World Wide Web How to Program, 5/e by Pearson Education, Inc. All Rights Reserved.

Server side basics CS380

PHP. Introduction. PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server

CSI33 Data Structures

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

Programming for the Web with PHP

CGS 3066: Spring 2015 JavaScript Reference

Lecture 7 PHP Basics. Web Engineering CC 552

PHP Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Typescript on LLVM Language Reference Manual

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Visual C# Instructor s Manual Table of Contents

EL2310 Scientific Programming

PHP Hypertext Preprocessor

Course Outline. Introduction to java

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

Chapter 1 INTRODUCTION

CSC Web Programming. Introduction to JavaScript

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

COMS 469: Interactive Media II

INFS 2150 Introduction to Web Development and e-commerce Technology. Programming with JavaScript

Objectives. Introduction to JavaScript. Introduction to JavaScript INFS Peter Y. Wu, RMU 1

Operators. Java operators are classified into three categories:

Scripting Languages. Diana Trandabăț

COMP284 Scripting Languages Lecture 14: JavaScript (Part 1) Handouts

Java+- Language Reference Manual

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Programming Language Basics

COMP284 Scripting Languages Lecture 15: JavaScript (Part 2) Handouts

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Introduction of PHP Created By: Umar Farooque Khan

Working with JavaScript

Agenda. 1. Brief History of PHP. 2. Getting started. 3. Examples

IPCoreL. Phillip Duane Douglas, Jr. 11/3/2010

Pace University. Fundamental Concepts of CS121 1

And Parallelism. Parallelism in Prolog. OR Parallelism

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

B. V. Patel Institute of BMC & IT 2014

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

9.2 Linux Essentials Exam Objectives

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Language Reference Manual

<script type="text/javascript"> script commands </script>

Variables and Functions. ROBOTC Software

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

JavaScript Functions, Objects and Array

c122mar413.notebook March 06, 2013

Chapter 17. Fundamental Concepts Expressed in JavaScript

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Control Structures. A program can proceed: Sequentially Selectively (branch) - making a choice Repetitively (iteratively) - looping

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Java Notes. 10th ICSE. Saravanan Ganesh

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CERTIFICATE IN WEB PROGRAMMING

Alan Forbes - The Joy of PHP 1

CS313D: ADVANCED PROGRAMMING LANGUAGE

Chapter 2: Functions and Control Structures

CSE 303 Lecture 8. Intro to C programming

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

Key Differences Between Python and Java

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Preview from Notesale.co.uk Page 6 of 52

Full file at

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Python Input, output and variables

School of Information and Computer Technology Sirindhorn International Institute of Technology Thammasat University

CSCB20 Week 8. Introduction to Database and Web Application Programming. Anna Bretscher* Winter 2016

Programming for Engineers Iteration

PHPoC vs PHP > Overview. Overview

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

Chapter 2. Lexical Elements & Operators

Important Points about PHP:

Web Application Performance Testing with MERCURY LOADRUNNER

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Transcription:

PHP 1 Introduction Temasek Polytechnic

Background Open Source Apache License Free to redistribute with/without source code http://www.apache.org/license.txt Backed by Zend Corporation http://www.zend.com PHP web site http://www.php.net

Background Runs on many OS platform Linux, Mac OS X, Windows, Unix(es) Runs on many web server Apache, IIS, PWS, Xitami, AOL Server, and many more

PHP vs. Others ASP and ASP.NET Runs on Microsoft Windows OS and IIS web server only For other platform, available from Sun and not free (for ASP) JSP Longer development cycle Complexities of Enterprise level development ColdFusion Easy to use Not free

Background Open Source Software Free (money and mostly freedom) Mostly with liberal license http://www.opensource.org Free Software Free (money and freedom) Guarantee free and will always be free http://www.fsf.org

Background Many software that built the Internet is either Open Source or Free Servers: Email server: Sendmail, Exim, Postfix Web server: Apache, Tomcat Others: BIND (DNS Server) Programming GNU C/C++, Perl, Python, PHP (tons more) Database MySQL, PostgreSQL Web Application and Framework Zope, Nuke, JBoss Operating System Linux, FreeBSD

Client - Server Model In a client-server model, two computers work together to perform a task. A client computer request some information from a server computer. The server computer returns its information, and the client acts on it. The client requests a Web page from the server Client Server The server returns the Web page to the client

Client - Server Interaction for PHP The Web server plays a more active role when an PHP page is requested by the client. Client requests PHP file Server located the PHP file, parses it, removing PHP scripts & replacing it with HTML text Client Server Server returns HTML text to client

Starting PHP PHP syntax is derived from C, Perl, UNIX shell script Similarities with other syntaxes from other popular programming languages such as Java, Javascript, C, C++, Perl

PHP Pages HTML with PHP code embedded in it PHP code is enclosed in <?php // PHP code here?> Other form <? // PHP code here?>

PHP and HTML Combining PHP code and HTML <html> <head><title>set mood</title></head> <? $daytime = date("g", time()); if ($daytime < 12) {?> <body bgcolor="yellow"> <? } elseif($daytime >= 12) {?> <body bgcolor="blue"> <? }?> </body> </html>

Output as HTML Use the print or echo statement Example: <? print( Hello world! ); echo( Hello world! ); echo <h1>hello world!</h1> ; print Hello world!<br> ;?>

Statements and semicolons Statement A group or collection of code that performs a task when executed Semicolons All PHP statement MUST end with a semicolon ( ; ) Example: <?php phpinfo();?>

Comments Comments starts with either // (anything after this symbol is ignored) # (anything after this symbol is ignored) /* (anything inside this block is ignored) */ Examples: <?php // Prints the configuration info phpinfo();?>

Case Sensitivity PHP is not case sensitive, except PHP variable, however, is case sensitive Example the following two are the same print( This page rocks ); PriNt( This page rocks ); Example functions below are the same <?php PHPInfo(); phpinfo();?>

Variable You don t need to declare variable Variable name starts with $ Must start with alphabet or underscore ( _ ) Variable is case sensitive Example these three are not the same $name = Rasmus ; $Name = Rasmus ; $NaMe = Rasmus ; Example these are not legal $3stooges $?what // starts with? $store the total // space // starts with number

Number Integers Example: $a = 1000; $a = -999; Floats Example: $a = 1.234; $a = 1.2e3; $a = 7E-10;

Strings Represents free form text Uses either single quotes ( ) or double quotes ( ) Example: $a = Jack ; $b = Jill ; $c = This web site rocks!!! ; $d = What s up ; $e = I quote, Kopi take away ;

Strings Concatenation combining two or more strings Use. Example: $a = Hey ; $b = Jude ; $c = $a. $b; // Results: Hey Jude

Single vs. Double quotes Double quotes evaluates the variable within the quotes Single quotes doesn t Example: $a = it ; $b = Let $a be ; // results Let it be $c = Let $a be ; // results Let $a be

Boolean Boolean datatype has only two values: true or false Boolean value is not case insensitive Example: $a = True; // assigns TRUE to $a Integer can be converted to Boolean 0 means FALSE Non-zero means TRUE

Operators +, -, /, *, % ++, -- ==,!=! &&, <, >, <=, >= Arithmetic Increment, decrement Equality and inequality Logical NOT Logical AND and OR Less or greater than

Operators and its usage Example $a = 0; $a = $a + 1; // $a => 1 $a += 1; // same as above $a++; // same as above $b = 5 % 2; // yields 1 We ll discuss other operators in Control Structures section

Operators Precedence Which gets evaluated first? *, /, % +, - Example: $a = 2 + 3 * 4; // $a => 14 $a = (2 + 3) * 4; // $a => 20

Control Structures Selection and repetition are the building blocks of programming logic. Branch / Selection Selecting next instruction(s) based on a condition if, elseif, else Loop / Repetition Repeating next instruction(s) based on a condition while for foreach

Branch / Selection Uses boolean algebra to control the flow of execution A == B false true

if, elseif, else Construct if (condition 1) // statement elseif (condition 2) // statement else // statement Condition should evaluate to Boolean true or false elseif and else are optional

if, elseif, else Example: if ($phone == 98888888 ) print Lucky phone number ; elseif ($phone == 94444444 ) print Unlucky phone number ; else print Regular phone number ;

Conditional Test Test that yields boolean true or false Operators used: == for equality test!= for inequality test <, >, >=, <= for less, greater, exclusive and inclusive && the AND logical test the OR logical test

Binary logic AND OR true && true = true true && false = false false && true = false false && false = false true true = true true false = true false true = true false false = false

Conditional branching Example: if ($bp >= 80 && $bp <= 120) print Healthy blood pressure Example: $married = True; if (! $married) print Single ; Example: if ($age >= 60 $income < 30000 print Get social Security allowance

Block of code If if, elseif, and else is followed by more than one statement, curly braces must be used to group the statements together Failure to do so will likely not to cause syntax error, but logic error Example: if ($status == false) { $count++; print Login failed ; header( Location: index.htm ); }

Conclusion PHP basic syntax PHP control structure Branching Looping next week PHP shares some syntax similarities with other languages such as Java, Perl, C, and Unix shell script