Lab Homework #3 PHP Overview (based on by Lisa Wise)

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
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.
PHP Basics (See PHP on line manual at: PHP - Overview Scripting vs Programming Code Examples – PHP; Perl; JSP PHP Strengths.
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.
Guide To UNIX Using Linux Third Edition
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
 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.
1 CS428 Web Engineering Lecture 19 Data Types (PHP - II)
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
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.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
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.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
Intro to Web Programming using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000.
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.
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
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.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
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.
VB and C# Programming Basics. Overview Basic operations String processing Date processing Control structures Functions and subroutines.
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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.
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
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
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.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Chap 2 – Getting Started COMP YL Professor Mattos.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
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,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
Scott Marino MSMIS Summer Session Web Site Design and Authoring Session 13 Scott Marino.
PHP using MySQL Database for Web Development (part II)
>> Introduction to JavaScript
PHP (Session 1) INFO 257 Supplement.
Introduction to Dynamic Web Programming
DBW - PHP DBW2017.
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
PHP Introduction.
JavaScript.
PHP.
Web Programming Language
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
PHP an introduction.
Presentation transcript:

Lab Homework #3 PHP Overview (based on by Lisa Wise) CS 183 4/20/2010

Lab Homework #3 More CSS practice ◦ Add CSS to your HTML page from homework #0 ◦ Make it look nice! ◦ Get creative with available CSS styles ◦ No restrictions, but expect usage of a few elements that we discussed in class (e.g., class, ID, contextual selector, inheritance, …) CSS file should be external and included in head using tag (same as in previous lab) Due Date: 4/21 – EOD Submission: ◦ URL to your file via ◦ Send to Ryan

PHP PHP is a scripting language that allows you to create dynamic web pages You can embed php scripting within normal html coding PHP was designed primarily for the web PHP includes a comprehensive set of database access functions

Scripting vs. Programming A script is interpreted line by line every time it is run A true programming language is compiled from its human readable form (source code) into a machine readable form (binary code) which is delivered to the user as a program. Variables in scripting languages are type-less whereas variables in programs need to be declared as a particular type and have memory allocated to them. PHP requires programming skills PHP web sites should be developed within a software engineering framework

Competitors Perl Microsoft Active Server Pages (ASP) Java Server Pages (JSP) Allaire Cold Fusion

PHP Code Examples <?php $name = "Lisa"; $date = date ("d-m-Y", time()); ?> Hello World Hello World It's and all is well. <?php echo " Hello ".$name.". \n"; ?>

Perl Coding Example #!/usr/local/bin/perl print "Content-type: text/html \n\n"; $date = `/usr/local/bin/date`; $name = "Lisa"; print " "; print " Hello World "; print " \n "; print " Hello World "; print " It\'s $date and all is well "; print " Hello $name "; print " ";

JSP Coding Example page language="java" contentType="text/html" %> <%! String name = "Lisa" %> Hello World Hello World It's and all is well. Hello.

PHP Strengths High performance - see benchmarks at Interfaces to different database systems Low cost SourceForge has PHPTriad (Apache, PHP and MySQL) for WindowsPHPTriad Ease of learning and use Portability

Basics of PHP PHP files end with.php other places use.php3.phtml.php4 as well PHP code is contained within tags Canonical: Short-open: HTML script tags: We recommend canonical tags so as not to confuse with xml tags

Included Files Files can be inserted into other files using include or require These files can have any name and be anywhere on the filesystem so long as the file trying to include them has appropriate rights CAVEAT: ◦ if these files are not called blah.php, and they are fetched independently by a browser, they will be rendered in plaintext rather than passed to the PHP interpreter - not good if they contain username/passwords and things like that

Variables All variables begin with $ and can contain letters, digits and underscore (and no digit directly after the $) The value of a variable is the value of its most recent assignment Don’t need to declare variables Variables have no intrinsic type other than the type of their current value Can have variable variables $$variable

Variables Scopes Scope refers to where within a script or program a variable has meaning or a value Mostly script variables are available to you anywhere within your script. Note that variables inside functions are local to that function and a function cannot access script variables outside the function even if they are in the same file. The modifiers global and static allow function variables to be accessed outside the function or to hold their value between function calls respectively.

Output Most things in PHP execute silently You need to explicitly ask PHP to generate output Echo is not a function and cannot return a value echo " This is a paragraph. "; Print is a function and returns a value ◦ 1 = success ◦ 0 = failure print (" This is a paragraph too. "); Use echo or print statements and View Source for debugging your code

Variable Types Strings Numbers integers doublesintegersdoubles Booleans ◦ TRUE / FALSE Arrays Objects

Boolean Unlike PHP3, PHP4 has a boolean type if (TRUE) print ("This will always print"); A number is FALSE if it exactly equals 0 otherwise it is TRUE A string is FALSE if it is empty (has zero characters) or is "0" otherwise it is TRUE An array or object is FALSE if it contains no other values and is TRUE otherwise

Strings Dot operator for concatenation (joining) ◦ “test”. “file” singly quoted read in and store literally double quoted ◦ certain sequences beginning with \ are replaced with special characters + \n \t \r \$ \" \\ ◦ Variable names are replaced with string representations of their values (variable interpolation)  $name = "Praveen";  print "$name said Hello World to the crowd of people."; No limit on string length

String Functions boolean strcmp ($str1, $str2) boolean strcasecmp ($str1, $str2) boolean strstr ($haystack, $needle) ◦ case sensitive ◦ Returns the portion of string, or FALSE if needle is not found boolean stristr ($haystack, $needle) int strlen($str) string substr ($str, $start_pos, $len)

String Functions (cont) string chop ($str) ◦ Alias of rtrim() string ltrim ($str) string trim ($str) string str_replace ($old_txt, $new_txt, $text) string substr_replace ($old_txt, $new_txt, $text)

String Functions (cont) strtolower($str) strtoupper($str) ucfirst($str) ucwords($str) these last two don’t correct inappropriate upper case to lower case

String Parsers string strtok($str, $delimiter) $token = strtok ($str, $delimiter) while ($token) { print ($token." "); $token = strtok ($delimiter); } array explode ($delimiter, $str) ◦ Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter. boolean ereg ($reg_exp, $str, [,$array]) array split ($reg_exp, $str [, $num]) ◦ Splits a string into array by regular expression (deprecated)

Screening user input/output addslashes($str) ◦ Returns a string with backslashes before characters that need to be quoted in database queries etc. stripslashes($str) magic_quotes_gpc($str) ◦ Affects HTTP Request data (GET, POST, and COOKIE). Cannot be set at runtime, and defaults to on in PHP magic_quotes_runtime($query) ◦ If enabled, most functions that return data from an external source, including databases and text files, will have quotes escaped with a backslash. escapeshellcmd($str) ◦ escapeshellcmd() escapes any characters in a string that might be used to trick a shell command into executing arbitrary commands. strip_tags($str) ◦ This function tries to return a string with all NUL bytes, HTML and PHP tags stripped from a given str htmlspecialchars($str) ◦ Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. htmlentities($str) ◦ all characters which have HTML character entity equivalents are translated into these entities. nl2br($str) ◦ Returns string with ' ' or ' ' inserted before all newlines.

Math Functions + - / * % = -= *= = is set to = = is equivalent to = = = is identical to

Math Functions (Cont) $low_int = floor ($double) $high_int = ceil ($double) $nearest_int = round ($double) (nearest even number if exactly.5) $positive = abs ($number) $min = min ($n1, $n2 …, $nn) $max = max ($n1, $n2 …, $nn)

Control and Flow if (expr1) { } elseif (expr2) { } else { } while (cond) { } do { } while (cond) switch ($var) case a { } case b { } for ($i = 0; $i < expr; $i ++) { } foreach (array_expr as $value) { } foreach (array_expr as $key=>$value) { } break [1] continue

Next Topics … Arrays Forms Include / Require Coding style Classes Web-enabled Databases Session management Building code libraries