November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

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.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
IST 221 Internet Concepts and Applications Introduction to PHP.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
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.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
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”
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 03.
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.
PHP: Hypertext Processor Fred Durao
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.
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 MOHAMMED SHURRAB TO MISS/ RASHA ATTALLAH. What is PHP? Stands for "PHP Hypertext Preprocessor" Server-side scripting language HTML-embedded Supports.
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.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
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.
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.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Introduction to PHP Advanced Database System Lab no.1.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Oktober 2002Bent Thomsen - FIT 1-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript Syntax, how to use it in a HTML document
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.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Introduction to PHP.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
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.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
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.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
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,
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
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.
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 Basics and Syntax Lesson 3 ITBS2203 E-Commerce for IT.
PHP using MySQL Database for Web Development (part II)
Introduction to Dynamic Web Programming
CHAPTER 5 SERVER SIDE SCRIPTING
PHP Introduction.
WEB PROGRAMMING JavaScript.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Tutorial 10: Programming with javascript
Introduction to PHP.
PHP an introduction.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet

November 2003Bent Thomsen - FIT 6-12 Introduction to PHP Bent Thomsen

November 2003Bent Thomsen - FIT 6-13 What is PHP? PHP is a generalized Open Source Server Side Scripting Language that generates HTML content PHP: Recursive Acronym for –PHP: Hypertext Preprocessor PHP was created by Rasmus Lerdorf in 1994 as a tool for Web Development PHP is simple for beginners, yet a powerful tool for the professional Web Developer

November 2003Bent Thomsen - FIT 6-14 Embedding PHP in HTML is different from writing a script or program in other languages like Perl, Java or C#, but similar to JavaScript Instead of writing a program with lots of commands to output HTML, you write an HTML script with some embedded code to do something (in the example on the next page, to output some text). The PHP code is enclosed in start and end tags that allow you to jump into and out of "PHP mode". An example follows

November 2003Bent Thomsen - FIT 6-15 Embedding PHP in HTML A PHP Example First PhP Script <?PHP print(“Hello World”); ?>

November 2003Bent Thomsen - FIT 6-16 PHP Structures A PHP script begins (and ends) with a tag that inform the Web server that it is dealing with a PHP program. This tag is represented as –Alternatively, you can use: … A PHP script is save as a *.php file

November 2003Bent Thomsen - FIT 6-17 Continue … Every script-line must ends with a semi- colon (;) Documentation can be added using the “//” or “/* … */” comment tags –“ // ” for single line comment –“ /*…*/ ” for multiple lines comment

November 2003Bent Thomsen - FIT 6-18 PHP Script Example <?php // This is a very simple script that simply // output the sentence “Hello World!” print (“Hello World!”); ?> Opening Tag Comment Closing Tag Semi-colon

November 2003Bent Thomsen - FIT 6-19 PHP Program In general, a program consists of commands and values. –Commands: what the program can do. –Values are the information that commands are performed with. PHP is no exception. e.g. print (“Hello”); This statement performs the print() command using the value “Hello”

November 2003Bent Thomsen - FIT Print() Function Print () is use to send text to the browser. Another function, echo() behaves the same as Print(). Print() can also be use to send HTML formatted text to the browser. –Print(“ Hello World ”);

November 2003Bent Thomsen - FIT PHP vs. JavaScript What distinguishes PHP from client-side JavaScript? PHP code is executed on the server. If you were to have a script similar to the above on your server, the client would receive the results of running that script, with no way to determine what the underlying code may be.

November 2003Bent Thomsen - FIT Client-side execution using JavaScript Web-Server JavaScript WWW Web-Browser HTML Page Web-Client

November 2003Bent Thomsen - FIT Server-side execution using PHP Script Web-ClientWeb-Server PHP Script HTML-Form Submit Form Data Call PHP interpreter Response Web-Browser WWW Reply

November 2003Bent Thomsen - FIT PHP & Web Servers PHP supports most web servers including Apache Microsoft Internet Information Server Personal Web Server Netscape and iPlanet servers Oreilly Website Pro server Caudium, Xitami, OmniHTTPd For most servers PHP has a module, for the others supporting the CGI standard, PHP can work as a CGI processor.

November 2003Bent Thomsen - FIT PHP VARIABLES PHP keeps variables easy to work with Syntax is minimal All PHP variables start with $ Variable names are case sensitive Strings, integers, floating-point, arrays Variables generally come from 3 places –Assigned within a script –Passed from an HTML page –Or from the PHP environment

November 2003Bent Thomsen - FIT PHP VARIABLES PHP does not require explicit variable declarations Use a variable, and it exists! Examples of variable declaration in PHP –$a = “this is a string”; //this is a string –$b = 4; //this is an integer –$c = ; //this is a floating point number –$d = “5”; //this is another string

November 2003Bent Thomsen - FIT PHP Is Flexible $g = $b + $d ; echo $g will print 9 (See Preceding Slide) $m = 7; // $m is an integer $n = 1.732; // $n is double floating point $p = $m + $n; //$p is also a double floating point variable

November 2003Bent Thomsen - FIT The = sign Use = to indicate an assignment statement: –$X = 4; Use = = for comparison: –If($X==4);

November 2003Bent Thomsen - FIT More on Strings $my_name = “Peter”; $statement = “Hello, my name is $my_name”; –This expands the variable $my_name So the Echo $statement; Will print, “Hello, my name is Peter” If you want to include any of the following characters in your string you must first escape each with backslashes “ \ $

November 2003Bent Thomsen - FIT Operators Assignment ( = ) – returns a value equal to the value that was assigned: $a = ($b = 5); Arithmetic: + - * \ % Concatenation: “now”.“one String” Comparison: == != > >= < <= Logical: || or xor && and !

November 2003Bent Thomsen - FIT Operator Presedence (cast) * \ % + - >= == != && || = and xor or Can be changed by using parentheses e.g. 2*5+6 2*(5+6)

November 2003Bent Thomsen - FIT Constants You indicate that a label is to represent a constant by: define(‘CONSTANT_NAME’,value) or define(‘CONSTANT_NAME’,value,true) When the third parameter is present and true then the parameter label can be used in either upper or lower case e. g. define(‘PI’,3.1412,true) defines a constant PI and another pi that both have the value

November 2003Bent Thomsen - FIT Statements Function calls: print(“hello”); Assignment statements: $first = “first one”; If/Then/Else statement: if (expression){ true_part } else { false_part } While statement: while (expression) { repeated_part } For statement: for (init; test; update) { repeated_part }

November 2003Bent Thomsen - FIT If/Then/Else If/Then/Else statement: if (expression){ true_part } else { false_part } Used to conditional execute part of a PhP script The else part is optional Example: if ($num == 1) { $end = “st”; } else if ($num == 2 or $num ==3) { $end = “ed”; } else { $end = “th”; } print (((string)$num).$end);

November 2003Bent Thomsen - FIT While While statement: while (expression) { repeated_part } Loop, that is repeat all the enclosed PhP statements, while the condition is true Example: $count = 0; while ($count ”); $count = $count + 1; }

November 2003Bent Thomsen - FIT For For statement: for (init; test; update) { repeated_part } Execute the init statement, then test the condition; then repeat the loop In the loop, as long as the condition is true, execute the statements in the body; then execute the update statement; then test the condition Example: for ($n = 1; $n ”);}

November 2003Bent Thomsen - FIT Array Examples Creating a simple Array $class = array (“Web Programming II”, “CS463”, “MWF”); Creating an Associative Array $ranks (“first” =>1, “second” =>2, “third” =>3 ); Heterogeneous Array $studentA = array (“StudentA”, “Sr”, 3.4, 103); Printing echo class[2]; // echo out the second element: prints “CS463”; echo ranks[3]; // echo out the third element: prints 3; echo studentA[4]; // echo out the cumulative credits: prints 103;

November 2003Bent Thomsen - FIT Array - multidimensional creating $students = array( array( “StudentA”, “FR”, 3.0), array( “StudentB”, “JR”, 2.8), array( “StudentC”, “SR”, 3.3) ); Printing print $student[2][0]; //prints “StudentC” More sophisticated? $students2 = array( “StudentA” => array( “Year”=>”FR”, “GPA”=>3.0), “StudentB” => array( “Year”=>”JR”, “GPA”=>2.8), “StudentC” => array( “Year”=>”SR”, “GPA”=>3.3) ); Printing print $students2[“StudentB”][“GPA”]; // prints 2.8

November 2003Bent Thomsen - FIT Functions Functions denote actions that can be taken (on your behalf) by php Example print(“This is some text”); Functions can be parts of an expression Functions have one or more arguments (the part inside the parentheses) The values of the arguments are past to the functions that do something with them (“side effects”) A Function may return a value (example shortly)

November 2003Bent Thomsen - FIT More Functions Built-in functions: –print, round, sqrt, cos, rand, … Use defined functions function diff($par1,$par2){ if ($par1 > $par2){ return $par1 - $par2; } else { return $par2 - $par1; }

November 2003Bent Thomsen - FIT An example <?php /* First define functions use them later */ function diff($par1,$par2){ if ($par1 > $par2){ return $par1 - $par2; } else { return $par2 - $par1; } echo “The difference between 5 and 10 is”; echo diff(5,10); ?>