PHP by Pearson Education, Inc. All Rights Reserved.

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

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

WINTER. Web Development. Template. PHP Variables and Constants. Lecture

B. V. Patel Institute of BMC & IT 2014

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

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

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

CSC Web Programming. Introduction to JavaScript

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

PHP and MySQL for Dynamic Web Sites. Intro Ed Crowley

PHP. Interactive Web Systems

JavaScript Functions, Objects and Array

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

Web Engineering (Lecture 08) WAMP

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

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

Lecture 12. PHP. cp476 PHP

JavaScript CS 4640 Programming Languages for Web Applications

PHP 1. Introduction Temasek Polytechnic

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

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

JavaScript CS 4640 Programming Languages for Web Applications

Chapter 2, Part I Introduction to C Programming

Web Scripting using PHP

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Server side basics CS380

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:

Princess Nourah bint Abdulrahman University. Computer Sciences Department

The C++ Language. Arizona State University 1

PHP Hypertext Preprocessor

Introduction of PHP Created By: Umar Farooque Khan

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

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

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

JavaScript I Language Basics

3 The Building Blocks: Data Types, Literals, and Variables

In addition to the primary macro syntax, the system also supports several special macro types:

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to the World Wide Web (cont d.) Introduction to the World Wide Web

Chapter 2: Introduction to C++

Fundamentals of Programming Session 4

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

(Refer Slide Time: 01:12)

Pathologically Eclectic Rubbish Lister

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Chapter 11 Outline. A Simple PHP Example Overview of Basic Features of PHP Overview of PHP Database Programming. Slide 11-2

PHPoC Language Reference > Overview. Overview

PHP Introduction. Some info on MySQL which we will cover in the next workshop...

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Lecture 7 PHP Basics. Web Engineering CC 552

General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

Course Syllabus. Course Title. Who should attend? Course Description. PHP ( Level 1 (

php Mr. Amit Patel Hypertext Preprocessor Dept. of I.T.

Chapter 2: Functions and Control Structures

Web Scripting using PHP

C++ Programming: From Problem Analysis to Program Design, Third Edition

A control expression must evaluate to a value that can be interpreted as true or false.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

CHIL CSS HTML Integrated Language

JavaScript: Introductionto Scripting

PHP INTERVIEW QUESTION-ANSWERS

Client-Side Web Technologies. JavaScript Part I

CGS 3066: Spring 2015 JavaScript Reference

JavaScript: The Basics

PHPoC vs PHP > Overview. Overview

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

Expr Language Reference

CERTIFICATE IN WEB PROGRAMMING

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

egrapher Language Reference Manual

Web Site Design and Development JavaScript

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

UNIT -II. Language-History and Versions Introduction JavaScript in Perspective-

CSCE 120: Learning To Code

Typescript on LLVM Language Reference Manual

- Origins - Rasmus Lerdorf Developed to allow him to track visitors to his Web site

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

Introduction to MATLAB

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Lecture 2 Tao Wang 1

Instructor s Notes Web Data Management PHP Sequential Processing Syntax. Web Data Management PHP Sequential Processing Syntax

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Course Outline. Introduction to java

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++

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

IT 374 C# and Applications/ IT695 C# Data Structures

Creating a C++ Program

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list.

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

Using the Command-Line Interface

Chapter 1 INTRODUCTION

2 nd Week Lecture Notes

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

Perl Regular Expressions. Perl Patterns. Character Class Shortcuts. Examples of Perl Patterns

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Transcription:

PHP 1992-2012 by Pearson Education, Inc. All

Client-side Languages User-agent (web browser) requests a web page JavaScript is executed on PC http request Can affect the Browser and the page itself http response Web page (with JavaScript) is sent to PC

Client-side What kind of things can you do with JavaScript? Validating Form information, i.e., making sure all the fields are complete before submitting data back to the server Modifying a web page based on Mouse Events. Can turn a web page into a user interface with interactive buttons and controls

Server-side Languages User-agent (web browser) requests a web page User never sees the PHP, only the output http request Cannot affect the browser or client PC http response Server detects PHP code in page, executes the code, and sends the output to the user Web page (with PHP Output) sent to PC

For making advanced dynamic web sites, you need some kind of server side scripting. Server side scripts are programs that are executed on the server, and can be used in many clients. PHP, or PHP: Hypertext Preprocessor, has become the most popular server-side scripting language for creating dynamic web pages. PHP is open source and platform independent implementations exist for all major UNIX, Linux, Mac and Windows operating systems. PHP also supports a large number of databases. 1992-2012 by Pearson Education, Inc. All

PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code are executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php" 1992-2012 by Pearson Education, Inc. All

PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in your database PHP can be used to control user-access PHP can encrypt data 1992-2012 by Pearson Education, Inc. All

The power of the web resides not only in serving content to users, but also in responding to requests from users and generating web pages with dynamic content. PHP code is embedded directly into text-based documents, such as HTML, though these script segments are interpreted by a server before being delivered to the client. PHP script file names end with.php. In PHP, code is inserted between the scripting delimiters <?php?>. PHP code can be placed anywhere in HTML5 markup, as long as the code is enclosed in these delimiters. 1992-2012 by Pearson Education, Inc. All

Variables are preceded by a $ and are created the first time they re encountered. PHP statements terminate with a semicolon (;). Single-line comments which begin with two forward slashes (//) or a pound sign (#). Text to the right of the delimiter is ignored by the interpreter. Multiline comments begin with delimiter /* and end with delimiter */. When a variable is encountered inside a double-quoted ("") string, PHP interpolates the variable. In other words, PHP inserts the variable s value where the variable name appears in the string. All operations requiring PHP interpolation execute on the server before the HTML5 document is sent to the client. PHP variables are loosely typed they can contain different types of data at different times. 1992-2012 by Pearson Education, Inc. All

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) 1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

Type conversions can be performed using function settype. This function takes two arguments a variable whose type is to be changed and the variable s new type. Variables are typed based on the values assigned to them. Function gettype returns the current type of its argument. Calling function settype can result in loss of data. For example, doubles are truncated when they are converted to integers. When converting from a string to a number, PHP uses the value of the number that appears at the beginning of the string. If no number appears at the beginning, the string evaluates to 0. 1992-2012 by Pearson Education, Inc. All

Another option for conversion between types is casting (or type casting). Casting does not change a variable s content it creates a temporary copy of a variable s value in memory. The concatenation operator (.) combines multiple strings. A print statement split over multiple lines prints all the data that is enclosed in its parentheses. 1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

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 1992-2012 by Pearson Education, Inc. All

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): <?php $x = 5; $y = 10; function mytest() { global $x, $y; $y = $x + $y; } mytest(); echo $y; // outputs 15?> 1992-2012 by Pearson Education, Inc. All

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: <?php function mytest() { static $x = 0; echo $x; $x++; } mytest(); // outputs 0 mytest(); // outputs 1 mytest(); // outputs 2?> 1992-2012 by Pearson Education, Inc. All

A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). To create a constant, use the define() function. It takes two arguments the name and value of the constant. An optional third argument accepts a boolean value that specifies whether the constant is case insensitive constants are case sensitive by default. define(name, value, case-insensitive); define("greeting", "Welcome to W3Schools.com!"); 1992-2012 by Pearson Education, Inc. All

Uninitialized variables have undefined values that evaluate differently, depending on the context. In a numeric context, it evaluates to 0. In contrast, when an undefined value is interpreted in a string context (e.g., $nothing), it evaluates to the string "undef". Keywords may not be used as function, method, class or namespace names. 1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

PHP provides the capability to store data in arrays. Arrays are divided into elements that behave as individual variables. Array names, like other variables, begin with the $ symbol. Individual array elements are accessed by following the array s variable name with an index enclosed in square brackets ([]). If a value is assigned to an array element of an array that does not exist, then the array is created. Likewise, assigning a value to an element where the index is omitted appends a new element to the end of the array. Function count returns the total number of elements in the array. Function array creates an array that contains the arguments passed to it. The first item in the argument list is stored as the first array element (index 0), the second item is stored as the second array element and so on. 1992-2012 by Pearson Education, Inc. All

Arrays with nonnumeric indices are called associative arrays. You can create an associative array using the operator =>, where the value to the left of the operator is the array index and the value to the right is the element s value. PHP provides functions for iterating through the elements of an array. Each array has a built-in internal pointer, which points to the array element currently being referenced. Function reset sets the internal pointer to the first array element. Function key returns the index of the element currently referenced by the internal pointer, and function next moves the internal pointer to the next element. 1992-2012 by Pearson Education, Inc. All

The foreach statement, designed for iterating through arrays, starts with the array to iterate through, followed by the keyword as, followed by two variables the first is assigned the index of the element and the second is assigned the value of that index s element. (If only one variable is listed after as, it is assigned the value of the array element.) 1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

Many string-processing tasks can be accomplished using the equality and relational operators (==,!=, <, <=, > and >=). Function strcmp compares two strings. The function returns -1 if the first string alphabetically precedes the second string, 0 if the strings are equal, and 1 if the first string alphabetically follows the second. 1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All

1992-2012 by Pearson Education, Inc. All