Chapter 4 – The Building Blocks Data Types Literals Variables Constants.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
PHP Introduction.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Declaring Variables You must first declare a variable before you can use it! Declaring involves: – Establishing the variable’s spot in memory – Specifying.
JavaScript, Third Edition
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”
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
PHP : Hypertext Preprocessor
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Nael Alian Introduction to PHP
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Data types, Literals (constants) and Variables Data types specify what kind of data, such as numbers and characters, can be stored and manipulated within.
Variables, Operators and Data Types. By Shyam Gurram.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
1 PHP Introduction Chapter 1. Syntax and language constructs.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Introduction to PHP Advanced Database System Lab no.1.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Strings, output, quotes and comments
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
1 PHP Introduction Chapter 1. Syntax and language constructs.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Tharith Sriv.  JavaScript is a simple programming language that can be written directly into HTML documents to allow for increased interactivity with.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Creating PHP Pages Chapter 6 PHP Variables, Constants and Operators.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
 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.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
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,
Introduction to PHP and MySQL (Creating Database-Driven Websites)
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.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
Session 2 Basics of PHP.
PHP (Session 1) INFO 257 Supplement.
Receiving form Variables
Chapter 6 JavaScript: Introduction to Scripting
Variables Variables are used to store data or information.
Web Database Programming Using PHP
JavaScript Objects.
Web Technologies PHP 5 Basic Language.
PHP (PHP: Hypertext Preprocessor)
Intro to PHP & Variables
Java Programming: From Problem Analysis to Program Design, 4e
WEB PROGRAMMING JavaScript.
PHP.
Web DB Programming: PHP
PHP an introduction.
23 PHP.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Chapter 4 – The Building Blocks Data Types Literals Variables Constants

Data Types Specify what kind of data can be stored and manipulated within a program. – Core/Scalar (integer, float, string, boolean) – Special/Composite (arrays, objects, null, resources) Data are commonly stored in variables.

Numeric Literals PHP supports integers (do not contain decimal point) and floating-point numbers (must contain decimal point or exponent specifier). String Literals Row of characters enclosed in single or double quotes. An empty set of quotes is called the null string.

Here-docs Creates a block of text that simplifies writing strings containing lots of single quotes, double quotes, and variables. A user-defined delimiter starts and terminates the here-doc. The delimiter is preceded by three “<<<“ and must start with a letter or underscore.

Escape Sequences Consists of a backslash followed by a single character. \’Single quotation \”Double quotation \tTab \nNew Line \r Return/Line Feed \$Literal dollar sign \\Backslash \70Octal value \x05Hexadecimal character

Boolean Literals Logical values that have only one of two possible values, TRUE or FALSE (0 or 1; ON or OFF; Yes or No), both case insensitive. Used to test whether a condition is true or false.

Special Data Types Null – Represents “no value”. An uninitialized variable contains the value NULL. Resource – Holds a reference to an external resource such as a database object or file handler. (Will be discussed in Chapters 11 & 15). gettype() function -> Returns a string to identify the data type of its argument.

PHP Variables Start with a dollar sign ($), followed by a letter and any number of alphanumeric characters, including the underscore. $first_name = “Roberto”; $last_name = “Mattos”; Values assigned to variables can change throughout the run of a program. Initialization when declaring is not mandatory.

Displaying variables Print and Echo contructs (they are not functions) If a variable is enclosed in double quotes, it will be evaluated. In single quotes, it will not. Shortcut Tags Used to embed PHP within HTML portion of the file. Not recommended to use.

Variables and mixed Data Types PHP is loosely typed. You are not required to specify the type of data you are going to store in the variable when you declare it. At runtime the PHP interpreter will convert the data to the correct type

Concatenation and Variables Use the dot (.) to concatenate variables and strings together. PHP converts numeric values to strings.

References Assigning a value to a variable by reference -> one variable is an alias or pointer to another variable; they point to the same data. Changing one variable automatically changes the other. To assign by reference, prepend an ampersand (&) to the beginning of the old variable that will be assigned to the new variable.

Dynamic Variable It is a variable whose name is stored in another variable. Curly Braces ensure that PHP parser will evaluate the dollar signs properly.

Scope of Variables Local Variable -> exists only within a function. They are not available to the rest of the script. Global Variable -> accessible everywhere within a script other than from within functions. Superglobal Variable -> Special variables to help you manage forms, cookies, sessions and files and to get info about your environment and server.

Managing variables PHP provides a number of functions to help you manage variables. – isset() – returns true if variable has been set. – empty() – returns true if variable does not exist or has been assigned and empty string, 0 (zero as number), “0” (zero as string), NULL or no value at all. – is_bool() – is_double() – is_ object() – is_resource() – is_string() – unset()

Form Variables On php.ini file there is a directive called register_globals and it is set to OFF. Keep it that way for security reasons. You should add the following line of code to your php program, if you are dealing with forms: extract($_REQUEST); $_REQUEST is a superglobal array containing all the information submitted to the server from the HTML form.

Form Variables (cont.) For each HTML form parameter, PHP creates a global variable by the same name and makes it available to your script. Example of HTML input type: PHP creates a variable calles $your_name.

Predefined Variables PHP provides a number of predefined variables for describing the environment, server, browser, version, configuration file etc. Some are not fully documented as they depend on which server is running… phpinfo(INFO_VARIABLES); /* retrieve built in variables that have been set */ See full list of predefined variables at ed-Variables/8.php

Constants PHP provides its own predefined constants, but lets you create your own. A constant is a value that, once set, cannot be changed or unset during the execution of the script. They have global scope. It facilitates program maintenance. By convention, constants are capitalized. define() function creates a named constant. defined() function returns TRUE is constant has been set. constant() function returns the value of that constant.