PHP Variables.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

1 PHP  Introduction to PHP  Basic Syntax of PHP Variables, Constant, Data Type, Type Casting  Getting Data From Client  PHP Database Manipulation.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
Week 5 IBS 520. ColdFusion Variables CF uses variables to store data in memory. There are many different types of variables; each has its own.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Python Programming Chapter 2: Variables, expressions, and statements Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
Chapter 2 Beginning Problem-Solving Concepts for the Computer
Basic Input/Output and Variables Ethan Cerami New York
110-D1 Variables, Constants and Calculations(1) Chapter 3: we are familiar with VB IDE (building a form…) to make our applications more powerful, we need.
Identifiers and Assignment Statements. Data structures In any programming language you need to refer to data The simplest way is with the actual data.
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
PHP : Hypertext Preprocessor
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
1 PHP Variables. 2 What is a variable? A variable is something that can be changed – a thing that can take on any value from a possible set of values.
Introduction to Python
Variables, Assignment & Math Storing and naming data.
Nael Alian Introduction to PHP
A little PHP. Enter the simple HTML code seen below.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
Introduction to PHP Advanced Database System Lab no.1.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Strings, output, quotes and comments
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 3: Introduction to C: Input & Output, Assignments, Math functions.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part One.
CSD 340 (Blum)1 Starting JavaScript Homage to the Homage to the Square.
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.
The Basics Input / Output, and Primitive Data Types.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
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,
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
INT213 – WEEK 1 ASP tags and comments Variables, Constants, and "Literals" Simple Output.
JavaScript: Conditionals contd.
Chapter # 2 Part 2 Programs And data
Variables Variables are used to store data or information.
CHAPTER 5 SERVER SIDE SCRIPTING
Loops BIS1523 – Lecture 10.
PHP (PHP: Hypertext Preprocessor)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Presented By S.Yamuna AP/IT
Variables, Expressions, and IO
ITM 352 Expressions, Precedence, Working with Strings Class #5
PHP Introduction.
JavaScript.
Intro to PHP & Variables
IDENTIFIERS CSC 111.
Number and String Operations
WEB PROGRAMMING JavaScript.
PHP.
JavaScript What is JavaScript? What can JavaScript do?
Variables, Data Types & Math
Chapter # 2 Part 2 Programs And data
Variables, Data Types & Math
JavaScript What is JavaScript? What can JavaScript do?
Tutorial 10: Programming with javascript
Variables Lesson Outline
Evaluating Algebraic Expressions
Web Programming and Design
Getting Started in Python
Presentation transcript:

PHP Variables

What is a variable? A variable is something that can be changed – a thing that can take on any value from a possible set of values. For example, the number of hours someone works in a given week is a variable. In math, a symbol is used in place of the variable to express a relationship between some quantity and the variable For example, pay is one’s pay rate times the number of hours worked Pay = PayRate * NumberHours

What is a variable? (Cont.) So a variable is something that stands in for a quantity that might vary. In programming, a variable can be thought of a referring to a memory location or set of memory locations. The value of the variable at any given time is then the contents of that memory location As we said a variable can take on values from a set of possible values, the set of values is determined in part by the variable’s type.

Types Unlike many other programming languages, PHP variables do not have to be “declared.” In such a case, a variable’s types tends to come from its context. Standard types includes numbers (both integers and so-called floating point numbers that can have fraction parts. Another standard type is a string,which can used for names of things or just about any text.

PHP variable rules In PHP a variable starts with a dollar sign. After that must come a letter or an underscore (no numbers). After that can come letters or numbers. There can be no spaces in the name.

Assignment A variable is said to be assigned a value in an assignment statement. E.g. $NumberHours = 45; $WorkerFirstName = “Pete”; The assignment statement should not be thought of as expressing mathematical equality rather it a set of instructions to evaluate the expression on the right hand side and give the variable on the left hand side the value that results. Thus $Counter = $Counter + 1; Makes sense as an assignment statement even though it makes no sense as mathematics.

Turning DateDisplay into a program with a variable.

Result of DateDisplay as variable.

Incorporating variables within strings. print "The date is $dateString."; The above code also shows how variables are used in conjunction with strings in PHP. Within the string (set of characters within quotes) that will appear literally (“as is”), the variable does not appear as is, rather its value is substituted into the string.

If you don’t want the variable value substituted in, then use single quotes.

Result of single quoted version of DateDisplay.

That variable doesn’t vary much. Because these are PHP variables, all of their variation takes place on the server side (before the PHP preprocessed page is sent to the client). PHP variables will ultimately give us interaction with the viewer of the page but always through a process in which information is sent back to the server.

The bells, bells, bells example. Before consider variables determined by interaction with a user, let us consider one example in which the variable does vary. In Edgar Allen Poe’s poem The Bells, the word “bells” appears over and over again. Let’s substitute in an image of bells in place of the word bells. So far substitution (a lot of it) but not variation.

The bells, bells, bells example. (Cont.) The first part of the poem talks about silver bells, the second about gold bells, and so on. So in this example we will vary the image and the font color for each of the different parts.

Assigning the variables Writing some HTML A chunk of the poem, with the word bells replaced with the variable $bells. Note that the quotation can be spread out over many lines. (That would ne a no-no in C.) Re-assigning the variables

Where we left off. More of the same.

Silver bells turning into Golden bells as a result of our variable being reassigned.

Constants If you really want a quantity that is going to take on a value and never change then what you want is called a constant. Constants do not start with dollar signs. By convention, constant names are in all capital letters.

Pi page (code)

Pi page (in browser)

PHP’s Global Constants The <pre> tag tells HTML to respect the white space of the text between the tags. The function print_r is for printing arrays – GLOBALS is not one constant but a set of constants

Some of these constants tell one information about the PHP server – in this case the alpha.