Martin Kruliš 10. 12. 2015 by Martin Kruliš (v1.1)1.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

BY: ALBERTO CABEZAS 4/19/2010. INTRODUCTION: PHP is considered today as one of the most famous scripting languages. PHP is widely used as a general purpose.
Learning Web development. 3(+1) Tier architecture PHP script Remote services Web Server (Apache, IIS) Browser (IE, FireFox, Opera) Desktop (PC or MAC)
Javascript Client-side scripting. Up to now  We've seen a little about how to control  content with HTML  presentation with CSS  Javascript is a language.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
Intermediate PHP (1) Data Structures, Functions, Basic OO & Error Handling.
Guide To UNIX Using Linux Third Edition
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
UFCEKG-20-2 Data, Schemas & Applications Lecture 4 Server Side Scripting & PHP.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
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.
Copyright © Curt Hill PhP History and Introduction.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
ITD 3194 Web Application Development Chapter 4: Web Programming Language.

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.
PHP TUTORIAL. HISTORY OF PHP  PHP as it's known today is actually the successor to a product named PHP/FI.  Created in 1994 by Rasmus Lerdorf, the very.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
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.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
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.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
1Introduction to PHP 5 Presented by Brett Buddin.
PHP OVERVIEW. C ONTENT Introduction of PHP History and development Basics of PHP programming.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
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.
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,
CSE 154 LECTURE 14: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
CGS 3066: Web Programming and Design Spring 2016 PHP.
PHP WORKSHOP (Session 1) INFO 257 Supplement. Outline What is PHP ? PHP Language Basics PHP Exercise.
By bscshelp.com 1.  It is a group assignment.  Complete Website design Using Html and Css.  Due date: 10 th December, 2014 (Hard Deadline) 2.
Radoslav Georgiev Telerik Corporation
PHP Programming Language. PHP is a server-side scripting language designed for web development but also used as a general- purpose programming language.
CGS 3066: Web Programming and Design Spring 2017
PHP (Session 1) INFO 257 Supplement.
PHP for Server-Side Programming
CS 371 Web Application Programming
Java Primer 1: Types, Classes and Operators
DBW - PHP DBW2017.
PHP (PHP: Hypertext Preprocessor)
Introduction to PHP Martin Kruliš by Martin Kruliš (v1.1)
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
JavaScript an introduction.
PHP.
Python Primer 1: Types and Operators
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
PHP an introduction.
Presentation transcript:

Martin Kruliš by Martin Kruliš (v1.1)1

 PHP: Hypertext Preprocessor ◦ A powerful scripting language based on Perl syntax ◦ It was designed specifically for creating web pages  History ◦ 1994 Rasmus Lerdorf created set of scripts for maintaining his home page (which used CGI)  Designed in Perl, re-written in C for performance  Denoted “Personal Home Page/Forms Interpreter”  Released for public usage in 1995, community formed ◦ 1997 PHP/FI 2.0 released by Martin Kruliš (v1.1)2

 History ◦ 1997 Zeev Suraski and Andi Gutmans  Rewrote entire PHP parser (base for PHP 3)  Rebranded to “PHP: Hypertext Preprocessor” ◦ 1999 PHP core rewritten to Zend Engine ◦ 2000 PHP 4 released (based on Zend Engine 1.0)  OOP first introduced to PHP (in a bad way) ◦ 2004 PHP 5 released (Zend Engine II)  OOP completely redesigned  Current main branch (June 2013 PHP 5.5 released) ◦ PHP 7 was released very recently by Martin Kruliš (v1.1)3

 HTML Interleaving ◦ PHP script file is treated as text (HTML) document ◦ Contents between is treated as script  When the file is processed, the interpret removes script parts executes them and replaces them by their output  Script output is generated by echo or print()  Script controls prevail the HTML code  Short hand mark <? is equivalent of <?php and shorthand mark <?= is the same as <?php echo …  Pure PHP Scripts ◦ Must also start with <?php, but no ending mark is required (nor recommended) by Martin Kruliš (v1.1)4

 HTML Interleaving Example by Martin Kruliš (v1.1)5 PHP Example Conditional H1 PHP Example Conditional H Example 1

 Basic Syntax ◦ C-like syntax with relics from Perl  Statement separated by ';', blocks enclosed in {, }  Line comments //…\n, block comments /* … */  Standard control structures if (cond) stmt; elseif (cond2) stmt2; else... while (cond) stmt; do stmt; while (cond); for (init; cond; inc) stmt; foreach (array as [ $key => ] $value) stmt; ◦ Simple way to include files (both scripts and HTML)  include file; include_once file;  require file; require_once file; by Martin Kruliš (v1.1)6 Example 2

 Values and Data Types ◦ Values in PHP have explicit type  Scalar ( boolean, integer, float, or string )  Compound ( array, object )  Special ( resource, NULL ) ◦ Type can be tested by built-in functions  is_int(), is_string(), is_numeric(), is_scalar(), …  gettype() returns human-readable representation ◦ Type casting (explicit re-typing)  C-like syntax (type-name)expression ◦ Type juggling – automatic type casting by Martin Kruliš (v1.1)7

 Variables ◦ All variables are prefixed with ' $ ' symbol (e.g., $x ) ◦ No declarations, thus not statically defined type  Variable is created by the first assignment  Variable has the type of the value assigned to it ◦ Variables have function or global scope  Keyword global maps global variables in local scope ◦ Using non-existing variable generates notice  An the value is treated as null ◦ Functions for variable manipulation and testing: isset($var), unset($var), var_dump($var) by Martin Kruliš (v1.1)8 Example 3

 Constants ◦ Defined as superglobal (do not have scope) define("MYFOO", expression); echo MYFOO + 42; ◦ Magic constants (automatically defined)  Their value is related to their position in the code  __LINE__ - number of the script line  __FILE__ - name of the script file  __DIR__ - directory of the script file  __FUNCTION__ - name of the outer function  __CLASS__ - name of the outer class by Martin Kruliš (v1.1)9

 Expressions ◦ Almost every statement is an expression ◦ PHP has all standard C-like operators  Arithmetic, bitwise, logical, …  Identity operator (equality & type equality) ' === ', ' !== '  String concatenation is performed by dot '. ' ◦ String Literals  Single quoted strings ( 'text' ) – no special treatment  Double quoted strings ( "text" ) – interpreted  Special escaped characters ( \n, \r, \t, …)  Variables are replaced by their contents $a = 'foo'; $b = "Say $a\n"; by Martin Kruliš (v1.1)10 $b value is ‘Say foo’ (ended with newline)

 Arrays ◦ Array in PHP is an ordered map of key-value pairs  Can be used as array, list, hash table, dictionary, stack/queue, multi-dimensional array, or tree ◦ Defining arrays – array language construct $a1 = array(1, 2, 3); $a2 = array('foo' => 42, 'bar' => 54); ◦ Accessing elements echo $a1[1] + $a2['foo']; $a2['spam'] = 19; $a1[] = 4; unset($a1[2]); ◦ Each element may have different type by Martin Kruliš (v1.1)11 Prints ’44’ The following key is assigned $a1 ~ [0=>1, 1=>2, 3=>4]

 Arrays ◦ Each key can be either an integer or a string  Strings containing valid numbers are casted to integers  Floats are truncated and casted to integers  Booleans are casted to either 0 or 1  null is casted to an empty string  Arrays and objects cannot be used as keys ◦ Built-in functions for array manipulation  array_key_exists(), in_array()  array_push(), array_pop(), array_shift()  sort(), shuffle()  by Martin Kruliš (v1.1)12

 Functions ◦ Declaration  Keyword function followed by the identifier function foo([args, …]) { … body … }  The function body can be pretty much anything  Even nested function/class declaration  A value can yielded back by the return construct ◦ Invocation  foo(argument-expressions); by Martin Kruliš (v1.1)13 Example 4

 Objects and Classes ◦ PHP OOP mode is similar to classical object- oriented languages (Java, C#), but is also affected by concepts of dynamic scripting languages  Traditional classes with member definitions  Objects are hash-maps similar to arrays or JS objects ◦ Will be covered in the Advanced web technologies  Namespaces ◦ Logical (directory-like) wrappers for identifiers ◦ Affect classes, interfaces, constants, and functions ◦ Declared by namespace name; (at the beginning) by Martin Kruliš (v1.1)14

 Predefined Variables ◦ Request data, headers and, server settings are automatically parsed into superglobal arrays  $_GET – parameters from request URL  $_POST – parameters posted in HTTP body (form data)  $_FILES – records about uploaded files  $_SERVER – server settings and request headers  $_ENV – environment variables ◦ Example  index.php?foo=bar&arr[]=one&arr[]=two&  $_GET will look like array('foo' => 'bar', 'arr' => array('one', 'two')) by Martin Kruliš (v1.1)15

 HTTP Response ◦ Any output from the script is considered a response  Text outside script marks  Data written by echo or print() ◦ Headers may be modified by a function  header('header-line');  The modifications are parsed and moderated by the web server  The headers are sent as soon as any output is made  Beware the BOM signatures of unicode files by Martin Kruliš (v1.1)16 Example 5

 What is new in PHP 7 ◦ Improved performance and reduced memory usage ◦ Consistent 64-bit support ◦ AST-based compilation ◦ Many fatal errors converted to exceptions ◦ Removed old extensions SAPIs and some other backward-incompatible changes were made ◦ New features introduced  Anonymous classes  Zero cost asserts  Scalar and return type declarations by Martin Kruliš (v1.1)17

by Martin Kruliš (v1.1)18