Web Programming– UFCFB Lecture 19-20

Slides:



Advertisements
Similar presentations
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Advertisements

Creating PHP Pages Chapter 7 PHP Decisions Making.
PHP Introduction.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
Lecture 2 Introduction to PHP MIS 3501, Spring 2014 Jeremy Shafer Department of MIS Fox School of Business Temple University January 30, 2014.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Variables, Operators and Data Types. By Shyam Gurram.
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
CS346 Javascript -3 Module 3 JavaScript Variables.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Copyright Curt Hill Variables What are they? Why do we need them?
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Creating PHP Pages Chapter 5 PHP Structure and Syntax.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
ITM © Port, KazmanVariables - 1 ITM 352 Data types, Variables Class #4.
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.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Creating PHP Pages Chapter 10 PHP Arrays. Arrays An array can store one or more values in a single variable name. An element of an associative accessed.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
PHP using MySQL Database for Web Development (part II)
Session 2 Basics of PHP.
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
A variable is a name for a value stored in memory.
Chapter 10 Programming Fundamentals with JavaScript
Chapter 2 Variables.
Topics Designing a Program Input, Processing, and Output
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 6 JavaScript: Introduction to Scripting
ITM 352 Data types, Variables
Variables Variables are used to store data or information.
Chapter 2: Introduction to C++
Objectives In this chapter you will: Create PHP scripts
BASIC ELEMENTS OF A COMPUTER PROGRAM
JavaScript Objects.
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
JavaScript Syntax and Semantics
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2: Introduction to C++
IDENTIFIERS CSC 111.
Chapter 10 Programming Fundamentals with JavaScript
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
2.1 Parts of a C++ Program.
WEB PROGRAMMING JavaScript.
Chapter 2: Basic Elements of Java
Numbers.
Chapter 2 Variables.
PHP.
C++ Data Types Data Type
Chapter 2: Java Fundamentals
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
elementary programming
Chapter 2: Introduction to C++.
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Primitive Types and Expressions
Chapter 2 Variables.
Variables and Constants
Presentation transcript:

Web Programming– UFCFB3-30-1 Lecture 19-20 Instructor : Mazhar H Malik Email : mazhar@gcet.edu.om Global College of Engineering and Technology

PHP Variables, Constants and Operators Creating PHP Pages PHP Variables, Constants and Operators

Basic PHP Variables The values stored in computer memory are called variables The values, or data, contained in variables are classified into categories known as data types The name you assign to a variable is called an identifier

PHP Variables Prefixed with a $ Assign values with = operator Example: $name = “John Doe”; No need to define type Variable names are case sensitive $name and $Name are different

PHP Variables Variables are not statically typed Integers can become floats can become strings Variable types include : Boolean Integer Float String Array Object Resource NULL

Assigned by reference, this links vars PHP Variables Assigned by value $foo = "Bob"; $bar = $foo; Assigned by reference, this links vars $bar = &$foo; Some are preassigned, server and env vars For example, there are PHP vars, eg. PHP_SELF, HTTP_GET_VARS

Displaying Variables To display a variable with the echo statement, pass the variable name to the echo statement without enclosing it in quotation marks : $VotingAge = 18; echo $VotingAge; To display both text strings and variables, send them to the echo statement as individual arguments, separated by commas : echo "<p>The legal voting age is ", $VotingAge, ".</p>";

Naming Variables The name you assign to a variable is called an identifier The following rules and conventions must be followed when naming a variable: Identifiers must begin with a dollar sign ($) Identifiers may contain uppercase and lowercase letters, numbers, or underscores (_). The first character after the dollar sign must be a letter. Identifiers cannot contain spaces Identifiers are case sensitive

Declaring and Initializing Variables Specifying and creating a variable name is called declaring the variable Assigning a first value to a variable is called initializing the variable In PHP, you must declare and initialize a variable in the same statement: $variable_name = value;

PHP Constants Constants are special variables that cannot be changed Constant names do not begin with a dollar sign ($) Use them for named items that will not change Constant names use all uppercase letters Use the define() function to create a constant define("CONSTANT_NAME", value); The value you pass to the define() function can be a text string, number, or Boolean value

Standard Arithmetic operators String concatenation with a period (.) PHP Operators Standard Arithmetic operators +, -, *, / and % (modulus) String concatenation with a period (.) $car = “SEAT” . “ Altea”; echo $car; would output “SEAT Altea” Basic Boolean comparison with “==” Using only = will overwrite a variable value Less than < and greater than > <= and >= as above but include equality

Assignment (=) and combined assignment PHP Operators Assignment (=) and combined assignment $a = 3; $a += 5; // sets $a to 8; $b = "Hello "; $b .= "There!"; // sets $b to "Hello There!"; Bitwise (&, |, ^, ~, <<, >>) $a ^ $b(Xor: Bits that are set in $a or $b but not both are set.) ~ $a (Not: Bits that are set in $a are not set, and vice versa.)

Data Types A data type is the specific category of information that a variable contains Data types that can be assigned only a single value are called primitive types

Data Types PHP is not strictly typed A data type is either text or numeric PHP decides what type a variable is PHP can use variables in an appropriate way automatically E.g. $vat_rate = 0.175; /* VAT Rate is numeric */ echo $vat_rate * 100 . “%”; //outputs “17.5%” $vat_rate is converted to a string for the purpose of the echo statement Object and Array also exist as types

Numerics Data Types PHP supports two numeric data types: An integer is a positive or negative number and 0 with no decimal places (-250, 2, 100, 10,000) A floating-point number is a number that contains decimal places or that is written in exponential notation (-6.16, 3.17, 2.7541) Exponential notation, or scientific notation, is a shortened format for writing very large numbers or numbers with many decimal places (2.0e11)

Boolean Values A Boolean value is a value of TRUE or FALSE It decides which part of a program should execute and which part should compare data In PHP programming, you can only use TRUE or FALSE Boolean values In other programming languages, you can use integers such as 1 = TRUE, 0 = FALSE

References References : Anonymous.(n.d.). Apache HTTP Server Documentation Version 2.2. Retrieved from http://httpd.apache.org/docs/2.2/. Achour, M., Betz, F. (n.d.), PHP Manual. Retrieved from http://www.php.net/download-docs.php. Anonymous. (n.d.). MySQL Reference Manual. Retrieved from http://downloads.mysql.com/docs/. Naramore, E., Gerner, J., Le Scouarnec, Y., Stolz, J., Glass, M. K. (2005). Beginning PHP5, Apache, and MySQL® Web Development. Indianapolis, IN: Wiley Publishing, Inc.