PHP. What is PHP? PHP Hypertext Processor – Dynamic web development – Scripting language – Can be procedural or OOP(preferred) – PHP code can be embedded.

Slides:



Advertisements
Similar presentations
» PHP arrays are lists of values stored in key-value pairs. » Uses of arrays: Many built-in PHP environment variables. Database functions use arrays.
Advertisements

UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Introducing JavaScript
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Server side basics CS URLs and web servers  Usually when you type a URL in your browser:  Your computer looks up the server's IP address using.
Server side basics.
Server side basics CS URLs and web servers  Usually when you type a URL in your browser:  Your computer looks up the server's IP address using.
CMPT241 Web Programming Intro to PHP.
1 CS428 Web Engineering Lecture 19 Data Types (PHP - II)
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
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.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Form Handling.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)PHP Recap.
CSE 154 LECTURE 6: EMBEDDED PHP. PHP syntax template HTML content HTML content HTML content... PHP any contents of.
Lecture 12 PHP Basics Boriana Koleva Room: C54
INTERNET APPLICATION DEVELOPMENT For More visit:
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
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.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
CS320 Web and Internet Programming Introduction to PHP Chengyu Sun California State University, Los Angeles.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
PHP - 1h. How it works Client requests document Server loads document in memory Server processes document with relevant module (PHP) Server sends XHTML.
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.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Server-Side Scripting with PHP ISYS 475. PHP Manual Website
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
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.
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.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
CSE 154 LECTURE 15: EMBEDDED PHP. PHP syntax template HTML content HTML content HTML content... PHP any contents of.
CSE 154 LECTURE 16: FILE I/O; FUNCTIONS. Query strings and parameters URL?name=value&name=value...
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
Pemrogaman Web.  File handling is an important part of any web application. You often need to open and process a file for different tasks.
PHP using MySQL Database for Web Development (part II)
Lecture 16: File I/O; Functions
PHP for Server-Side Programming
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
CMPT241 Web Programming Intro to PHP.
PHP an introduction.
Presentation transcript:

PHP

What is PHP? PHP Hypertext Processor – Dynamic web development – Scripting language – Can be procedural or OOP(preferred) – PHP code can be embedded in XHTML code

Example <?php Echo “Hello There” ?> PHP interleaved <?php Echo “another php code ?> Save this file as filename.php

First PHP file <?php echo “Hello There”; ?> Save as filename.php Must serve through a server (Apache)

Lifecycle of a PHP web request

Web Browser Requests browser requests a.html file (static content): server just sends that file browser requests a.php file (dynamic content): server reads it, runs any script code inside – it, then sends result across the network – script produces output that becomes the response sent back

What if something went wrong in PHP? Identify the error Correct the error How do we know? Enable error logging

Setting up PHP Enable error display <?php // Turn off all error reporting error_reporting(0); // Report simple running errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Reporting E_NOTICE can be good too (to report uninitialized // variables or catch variable name misspellings...) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Report all errors except E_NOTICE error_reporting(E_ALL & ~E_NOTICE); // Report all PHP errors (see changelog) error_reporting(E_ALL); // Report all PHP errors error_reporting(-1); // Same as error_reporting(E_ALL); ini_set('error_reporting', E_ALL); ?>

PHP errors Can be done like this too error_reporting(E_ALL); ini_set('display_errors', 1); Or Set this in php.ini file in PHP folder display_errors = on

URLs and web servers – usually when you type a URL in your browser: your computer looks up the server's IP address using DNS your browser connects to that IP address and requests the given file – The web server software (e.g. Apache) grabs that file from the server's local file system, and sends back its contents to you

PHP Basics PHP can be used in Web pages and as a command line programming language(CLI) It can do most of the other programming languages do

PHP language Variables – $user_name = "PinkHeartLuvr78"; – $age = 16; – $drinking_age = $age + 5; – $this_class_rocks = TRUE;

PHP names are case sensitive; separate multiple words with _ names always begin with $, on both declaration and usage always implicitly declared by assignment (type is not written) a loosely typed language (like JavaScript or Python)

Basic PHP types int, float, boolean, string, array, object, NULL type-cast with (type): – $age = (int) "21";

Operators + - * / % = += -= *= /= %=.= == != === !== > = <= && || ! == just checks value ("5.0" == 5 is TRUE) === also checks type ("5" === 5 is FALSE) many operators auto-convert types: 5 < "7" is TRUE

Math operations $a = 3; $b = 4; – $c = sqrt(pow($a, 2) + pow($b, 2)); math functions – abs ceil cos floor log log10 max – min pow rand round sin sqrt tan math constants – M_PI M_E M_LN2

Comments # single-line comment // single-line comment /* multi-line comment */

String type $favorite_food = "Ethiopian"; print $favorite_food[2]; zero-based indexing using bracket notation string concatenation operator is. (period), not + – $fullname = $firstname.” “.$lastname

String functions $name = "Kenneth Kuan"; $length = strlen($name); # 12 $cmp = strcmp($name, "Jeff Prouty"); # > 0 $index = strpos($name, "e"); # 1 $first = substr($name, 8, 4); # "Kuan" $name = strtoupper($name); # "KENNETH KUAN„ Trim, explode, implode, substr, strcmp, strtolower

Interpreted strings $age = 16; – print "You are ". $age. " years old.\n"; – print "You are $age years old.\n"; # You are 16 years old. strings inside " " are interpreted – variables that appear inside them will have their values inserted into the string strings inside ' ' are not interpreted: – print 'You are $age years old.\n'; # You are $age years old.\n Resolve ambiguity – print "Today is your $ageth birthday.\n"; # $ageth not found – print "Today is your {$age}th birthday.\n";

loops for ($i = 0; $i < 10; $i++) { print "$i squared is ". $i * $i. ".\n"; } while (condition) { statements; } do { statements; } while (condition);

Conditions if (condition) { statements; } elseif (condition) { statements; } else { statements; }

NULL $name = "Victoria"; $name = NULL; if (isset($name)) { print "This line isn't going to be reached.\n"; } a variable is NULL if it has not been set to any value (undefined variables) it has been assigned the constant NULL it has been deleted using the unset function can test if a variable is NULL using the isset function NULL prints as an empty string (no output)

Bad and Good Ways Bad Good

Embedded PHP

PHP expression blocks

Embedded PHP

What is the output?

PHP Functions Parameter types and return types are not written

Calling a Function

Default Parameters Output

Variable Scope variables declared in a function are local to that function variables not declared in a function are global if a function wants to use a global variable, it must have a global statement

Including files: include() inserts the entire contents of the given file into the PHP script's output page encourages modularity useful for defining reused functions like form- checking

Arrays to append, use bracket notation without specifying an index element type is not specified; can mix types

Array Functions count($ar) array_pop($ar) array_push($ar,”element”) Array_reverse($ar)

The foreach loop

PHP file I/O functions reading/writing entire files: file_get_contents, file_put_contents asking for information: file_exists, filesize, fileperms, filemtime, is_dir, is_readable, is_writable, disk_free_space manipulating files and directories: copy, rename, unlink, chmod, chgrp, chown, mkdir, rmdir reading directories: scandir, glob

Read and Write Files

What is the output?

Reading Directories scandir returns an array of all files in a given directory annoyingly, the current directory (".") and parent directory ("..") are included in the array; you probably want to skip them