Session 2: PHP Language Basics iNET Academy Open Source Web Development.

Slides:



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

The Web Warrior Guide to Web Design Technologies
Lecture 2 Introduction to C Programming
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CMT Programming Software Applications
JavaScript, Third Edition
Introduction to C Programming
Basic Elements of C++ Chapter 2.
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”
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.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Nael Alian Introduction to PHP
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Variables, Operators and Data Types. By Shyam Gurram.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
1 Session 3: Flow Control & Functions iNET Academy Open Source Web Programming.
PHP and JavaScript Nov. 26, 2013 Kyung Eun Park Computer and Creativity (COSC109) Towson University.
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.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Introduction to PHP Advanced Database System Lab no.1.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
CS346 Javascript -3 Module 3 JavaScript Variables.
Strings, output, quotes and comments
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
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.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
FP512 WEB PROGRAMMING 1 PREPARED BY: PN. NUR SYUHADA BINTI MOHAMAD.
Chapter 3 Introduction to PHP. Incorporating PHP Within HTML By default, PHP documents end with the extension.php files ending with.htm or.html to also.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
 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.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
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.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Project 4: Working with Variables Essentials for Design JavaScript Level One Michael Brooks.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
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 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 6 JavaScript: Introduction to Scripting
Basic Elements of C++.
Exploring JavaScript Ch 14
JavaScript Syntax and Semantics
PHP Introduction.
Intro to PHP & Variables
Basic Elements of C++ Chapter 2.
Number and String Operations
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
elementary programming
23 PHP.
Presentation transcript:

Session 2: PHP Language Basics iNET Academy Open Source Web Development

Objectives PHP & HTML text Discuss variables’s definition, access, types and scope Discuss string’s definition, comparison and concatenation Discuss constants and predefined constants Discuss mathematical operations

Embedding PHP into HTML code

Comments Single line comment: // Multiline comment: start with /* and end with */ All PHP statements end with a semi-colon (;) Start a new line after your semi-colon

Variables A variable stores a value in memory In PHP, define a variable using the following form $variable_name = value; Rules of writing variable’s form The dollar sign ($) must fill the first place The first character after the $ must be either a letter (a-z|A-Z) or an underscore (_) Variable’s name is composed only of alphanumeric characters and underscore Variable’s in PHP are case-sensitive Variables with more than one word can be separated with underscores to make them easier to read Variables can be assigned values using the sign (=)

Variables (cont.) Assign value Reassign values Reading a variable’s value: specify the ($) followed by the variable’s name Variables are temporary. PHPautomatically cleans them when programs finish. Variable’s types: strings, numbers and arrays PHP handles data types automatically based on the context of using. Variable scope Variable’s value and type can be overwritten in a program Variable scope created by using function

Variables (cont.) Example of a variable scope To access a variable outside of a function, use global variable

Variables (cont.) Global variables Be carefull when using global variable If you want to use a variable in specific function without losing the value when the function ends, you would use static variable

Variables (cont.) Static variables are not destroyed when a function ends

Variables (cont.) Super global variables: provide information about PHP script’s environment defined in arrays since PHP 4.01

Strings Strings are sequences of individual characters String can be used directly in a function call or stored in a variable Strings are flexible Embed a variable in a string Single quotes are used if there are no embedded variables

Strings (cont.) Special characters: tab, new line, carriage return … To print special characters, string must use double quote and escaped characters Escape quotes within the string with a slash Use single quotes for quotes inside the string Start and end the string with single quotes

Strings (cont.) When single quote is used to define the string, double quotes don’t need to be escaped.

Strings (cont.) Comparing strings: use strcmp(string1, string2) function to compare two strings including the case Return value is 0 if two strings have the same text Nonzero value is returned if two strings are not the same use strcasecmp(string1, string2) function to compare two strings without comparing the case Return value is 0 if two strings have the same text Nonzero value is returned if two strings are not the same

Strings (cont.)

Concatenation: combines one or more text strings and variables. Use a period (.) to join variables and text strings. Can be done multiple times Combining a string with another data type results a new string

Constants A constant can not change its value during the execution of the program Constants are global and can be any simple data type Access a constant’s value using its name or using the constant function

Constants (cont.) Differences between constants and variables It’s common practice to capitalize a variable name for constants Constants do not have a dollar sign ($) at the start of their names Constants can be defined only by using the define function, not by simple assignment Constants are defined and accessed globally Constants cannot be redefined or undefined once they have been set Constants can evaluate only to scalar values

Constants (cont.) Predefined constants: similar to super global variables __FILE__ : returns the name of the PHP file being executed __LINE__ : returns the line number in that file __FUNCTION__ : the function name __CLASS__ : the class name __METHOD__ : the class method name

PHP basic mathematical operators

Combined Assignment Performing two common tasks at the same time Reading a variable’s value Performing operation on it Placing the result back in the same variable

Auto increment

Preincrement and -decrement

Practice In this practice, you will Download the session2_ex1.html from \\dc Replace the html corresponding to each row of the table with an echo statement Store the value of each cell in a variable Store the header’s content of the table in a constant