ITC 240: Web Application Programming SUBHASH PRAJAPATI 04/09/15.

Slides:



Advertisements
Similar presentations
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Outline What Is Function ? Create Function Call Function Parameters Functions Function Returning Values PHP Variable Scopes Passing by Reference Vs Value.
Functions in C++. Functions  Groups a number of program statements into a unit & gives it a name.  Is a complete and independent program.  Divides.
ITC 240: Web Application Programming
ITC 240: Web Application Programming SUBHASH PRAJAPATI 04/14/15.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Functions.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Chapter 2: Variables, Operations, and Strings CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
Java Programming, Second Edition Chapter Four Advanced Object Concepts.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
Introduction to Python
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Includes and Dates.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
1 Please switch off your mobile phones. 2 Data Representation Instructor: Mainak Chaudhuri
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Functions.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Keeping it Neat: Functions and JavaScript Source Files Chapter 7.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 16: PHP Types.
1 PHP Introduction Chapter 1. Syntax and language constructs.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
PHP Variables.  Variables are "containers" for storing information. How to Declare PHP Variables  In PHP, a variable starts with the $ sign, followed.
Functions Structured Programming. Topics to be covered Introduction to Functions Defining a function Calling a function Arguments, local variables and.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
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.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
Radoslav Georgiev Telerik Corporation
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
PHP using MySQL Database for Web Development (part II)
ITM 352 Data types, Variables
Variables Variables are used to store data or information.
Computing Fundamentals
Web Programming– UFCFB Lecture 19-20
PHP Introduction.
PHP.
JavaScript: Introduction to Scripting
PHP an introduction.
ITM 352 Functions.
Variables and Constants
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

ITC 240: Web Application Programming SUBHASH PRAJAPATI 04/09/15

Review Client Server Architecture Server Side Language/ Client Side Language PHP Fundamentals/Syntax Variable Function

Today More on Variables & Functions Scope Functions: parameters & returns, passing by values Conditionals

Variables Container that can hold certain value (storing data into memory location) Starts with $ sign A noun Starts with underscore or letter Can be named with a-z, A-Z, _, 0-9 characters cAsE sEnSiTivE - $myVar and $Myvar are different

Functions A block of code to perform a task Starts with “function” keyword A verb Can be named with a-z, A-Z, _, 0-9 characters NOT case sensitive – myfunction() & myFunction() are same, but good practice is just use one.

Constants An identifier with an associated value which cannot be altered by the program during normal execution. Written in all UPPER_CASE <?php define ("SALES_TAX",.096); $itemPrice = 50; echo $totalPrice = $itemPrice + ($itemPrice * SALES_TAX); ?>

Variable Types Boolean $booleanVar = TRUE; // a boolean String $stringVar = "foo"; // a string $stringVar = 'foo'; // a string Integer $integerVar= 12; // an integer Float $floatVar= 12.5; // a floating point number Others: Array, Objects, Resource, Null (we’ll discuss later)

Function Types User-defined Functions The functions we define Build in Functions The functions that come with PHP for eg: date(); date ( string $format [, int $timestamp = time() ] ) // returns string

PHP date () function A program to display today’s date <?php echo date (‘Y’); // displays the current year echo date (‘m’); // displays the current month echo date (‘d’); // displays today’s date echo (‘H:i:s’); // Hour, minute, seconds // automatic copyright © ?> Check PHP date manual for complete list of the possible parametersdate manual

Class Exercise 2.1 Write the output of following: <?php echo date('l jS \of F Y h:i:s A'). " "; echo date(‘Y-m-d H:i:s’). " "; ?>

Class Exercise 2.2 mktime (hour,minute,second,month,day,year) // returns unix timestamp <?php $date =mktime(10, 21, 45, 4, 11, 2012); echo "Created date is ". date("Y-m-d h:i:sa", $date); ?>

Class Exercise 2.3 strtotime (string) // pass English phrase <?php $date=strtotime("tomorrow"); echo date("Y-m-d h:i:sa", $date). " "; $date=strtotime("next Monday"); echo date("Y-m-d h:i:sa", $date). " "; $date=strtotime("+6 Months"); echo date("Y-m-d h:i:sa", $date). " "; ?>

Class Exercise 2.3 strtotime (string) // pass English phrase <?php $date=strtotime("tomorrow"); echo date("Y-m-d h:i:sa", $date). " "; $date=strtotime("next Monday"); echo date("Y-m-d h:i:sa", $date). " "; $date=strtotime("+6 Months"); echo date("Y-m-d h:i:sa", $date). " "; ?>

Typecasting gettype ()/ settype() – built in functions <?php $foo = '1'; echo gettype($foo); // outputs 'string' settype($foo, 'integer'); echo gettype($foo); // outputs 'integer‘ // another way $a = (int) ‘55’; ?>

Typecasting OperatorChanges to (int)Integer (bool)Boolean (string)String (array)Array (object)Object (unset)NULL

User defined functions: Parameters Parameters: arguments passed to a function <?php function calculateSomething ($firstNumber, $secondNumber){ // do some calculations here } ?> In above example, $firstNumber and $secondNumber are two parameters

User defined functions: Return Value Return Value: the value returned by the function <?php function addNumber ($firstNumber, $secondNumber){ $sum = $firstNumber + $secondNumber; return $sum; } ?> In above example $sum is the return value

User defined functions: Function Call Function Call: Just defining the function does NOT do anything, until you call it. function doSomeMagic ($magicName) { // magic code here } // function call doSomeMagic (‘awesome magic’);

Class Exercise 2.4 Write a program (a function) to converts Fahrenheit to Celsius temperature. (for example 45.5 F = 7.5 C) Formula: C = ((F-32) * (5/9)) Celsius Scale: Fahrenheit Scale:

Default parameter value <?php function orderDrink ($drink = “coffee") { // coffee is the default value return "Making a cup of $drink.\n"; } echo orderDrink (“Ice Tea"); echo orderDrink (); ?>

User defined Functions: return Function can also return without the value <?php function returnInMiddle () { // do something return; // code written here will not be executed } ?>

Variable Scope The variables inside user-defined function have local scope. Check output of following: <?php function addNumbers($a, $b){ $sum = $a + $b; return $sum; } echo $sum; $sum = addNumbers (5,6); echo $sum; ?>

Variable Scope The variables inside user-defined function have local scope. Check output of following <?php $myName = “Tina”; function printName(){ echo $myName; } printName (); ?>

Global Variable The variables inside user-defined function have local scope. Check output of following <?php $a = 1; $b = 2; function addNumbers () { global $a, $b; $sum = $a+$b; return $sum; } $sum = addNumbers (); echo $sum; ?>

Passing by reference We can pass a variable by reference to a function so the function can modify the variable <?php function incrementTheVariable(&$var){ $var++; } $a=5; incrementTheVariable($a); // $a is 6 here ?>