Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.

Slides:



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

PHP Introduction.
Introduction to PHP and MySQL Kirkwood Center for Continuing Education By Fred McClurg, © Copyright 2010, All Rights Reserved 1.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Chapter 2: Introduction to C++.
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”
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
A First Book of ANSI C Fourth Edition
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.
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.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
An Introduction to PHP The University of Tennessee at Chattanooga C. Daniel Chase “An introduction to basic PHP use with a focus on the power of dynamic.
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.
Variables, Operators and Data Types. By Shyam Gurram.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
Input, Output, and Processing
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
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,
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
PHP Constructs Advance Database Management Systems Lab no.3.
Week 4 PHP H ypertext P reprocessor Reference : Official Site :
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Strings, output, quotes and comments
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming basics.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
Chapter 2 Variables.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
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.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
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.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
 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.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
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.
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,
CGS 3066: Web Programming and Design Spring 2016 PHP.
Introduction to PHP and MySQL (Creating Database-Driven Websites)
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)
C++ First Steps.
>> Introduction to JavaScript
Chapter 2 Variables.
CHAPTER 5 SERVER SIDE SCRIPTING
PHP (PHP: Hypertext Preprocessor)
PHP Introduction.
Introduction to C++ Programming
PHP.
Chapter 2: Introduction to C++.
Tutorial 10: Programming with javascript
PHP an introduction.
Chapter 2 Variables.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics

Open Source Server Side Scripting 2 ECA 236 PHP Browser Server PHP.php Request Response Three types of errors can occur: 1.Parse 2.Execution 3.Logic

Open Source Server Side Scripting 3 ECA 236  4 different styles of PHP tags:  XML style  Short style  Script style  ASP style Basic Syntax

Open Source Server Side Scripting 4 ECA 236 Basic Syntax cont …  Files end with the extension.php  All statements end with a semicolon  White space is ignored  3 styles of comments: # comments // comments /* comments */

Open Source Server Side Scripting 5 ECA 236 Basic Syntax cont …  All class assignments must contain, in comments: Name Date Name of Assignment Purpose of Assignment /*Michael Barath 3 September 2003 Lab #3 Use loops and conditional to create and format a table */

Open Source Server Side Scripting 6 ECA 236 Variables  Naming Rules:  prefixed with a $  begin with letter or underscore  may contain only letters, number, underscores  case sensitive  Assign a value with the assignment operator ( = )  Do not have to be declared before use $first_name = “Michael”;

Open Source Server Side Scripting 7 ECA 236 Variables cont …  Variable Types  strings  integers  floating-point  Boolean  array  object  resources – special variable, holding a reference to an external resource such as an open file, database connection, or image canvas  NULL – a variable that has no value

Open Source Server Side Scripting 8 ECA 236 Sending data to browser  Built-in functions to send data to browser:  echo( ) allows you to send one or multiple pieces of code, separated by commas $first_name = “Michael”; $greeting = “How are you?”; echo “Hello, $first_name. $greeting”; echo “Hello, ”, $first_name, “.”, $greeting;

Open Source Server Side Scripting 9 ECA 236 Sending data to browser cont …  Built-in functions to send data to browser:  print( ) returns a value of TRUE or FALSE, if the function was called successfully  Technically neither echo( ) nor print( ) is a true function, but a language construct $first_name = “Michael”; $greeting = “How are you?”; print “Hello, $first_name. $greeting”;

Open Source Server Side Scripting 10 ECA 236 Strings  Blocks of textual information  Double Quotes  interpolated variables $name = “Michael”; echo “My name is $name”; // prints “My name is Michael”

Open Source Server Side Scripting 11 ECA 236 Strings cont …  Single Quotes  literals $name = “Michael”; echo ‘My name is $name’; // prints “My name is $name”

Open Source Server Side Scripting 12 ECA 236 Strings cont …  Use \ to escape quotes, $, \, etc $name = “Michael”; echo “$name said, \”Bob owes me \$20.\” ”; // prints Michael said, “Bob owes me $20.” echo ‘Michael\’s reply was “What, me worry?” ’; // prints Michael’s reply was “What, me worry?”

Open Source Server Side Scripting 13 ECA 236 Strings cont …  Concatenation Operator  dot, or period $first_name = “Jacques”; $last_name = “Renault”; echo $whole_name = $first_name. $last_name; // prints JacquesRenault echo $whole_name = $first_name. “ “. $last_name; // prints Jacques Renault

Open Source Server Side Scripting 14 ECA 236 Strings cont …  newlines and tabs \n \t  adds returns or tabs to the way code prints, not the way a document renders in the browser echo “ My Title ”; // prints My Title

Open Source Server Side Scripting 15 ECA 236 Strings cont …  newlines and tabs cont … echo “ \n \n\t My Title \n ”; /* prints My Title */

Open Source Server Side Scripting 16 ECA 236 Strings cont …  newlines and tabs cont … echo “ ”; echo “\t My Title ”; echo “ ”; /* prints My Title */

Open Source Server Side Scripting 17 ECA 236 Numbers  integer and floating point  Standard arithmetic operators: +addition –subtraction *multiplication /division $x = 7; $y = 3; $z = $x * $y ; // 21

Open Source Server Side Scripting 18 ECA 236 Numbers cont …  Standard arithmetic operators: %modulus  remainder, after division has occurred $x = 7; $y = 3; $z = $x % $y ; // 1

Open Source Server Side Scripting 19 ECA 236 Numbers cont …  Standard arithmetic operators: + +increment – –decrement $x = 7; echo $x++ ; // prints 7 echo ++$x ; // prints 8 $x = 7; echo $x- - ; // prints 7 echo - - $x ; // prints 6

Open Source Server Side Scripting 20 ECA 236 Numbers cont …  PHP includes dozens of functions to use with numbers. EG:  round( ) – rounds a decimal to the nearest integer takes one or two arguments  number to be rounded  number of decimal places $x = ; $x = round( $ ); // 313 $x = round( $x, 3 ); // $x = round( $x, - 2 ); // 300

Open Source Server Side Scripting 21 ECA 236 Numbers cont …  PHP includes dozens of functions to use with numbers. EG:  number_format( ) – groups number into thousands, comma takes one or two arguments  number to be formatted  number of decimal places $x = ; $x = number_format( $x ); // 43,905 $x = number_format( $x, 2 ); // 43,905.31

Open Source Server Side Scripting 22 ECA 236 Variables and CONSTANTS  CONSTANTS  Unlike variables, retain initial value throughout script  Use define( ) to create  Constants are usually named with all CAPS  No $ prefixes a CONSTANT  Cannot use echo( ) as you would with variables define( ‘NAME’, ‘Michael’ ); echo “Hello, “, NAME ; echo “Hello, “. NAME ;

Open Source Server Side Scripting 23 ECA 236 PHP’s Predefined Variables Superglobals  $_SERVER  $_GET  $_POST  $_COOKIE  $_FILES  $_ENV  $_REQUEST  $_SESSION

Open Source Server Side Scripting 24 ECA 236 Variable Scope  Superglobal variables are visible everywhere  Global variables within a script are visible throughout the script, but not inside functions  Variable used inside functions are local to the function  Variables used inside a function that are declared as global, refer to the global variables of the same name