Download presentation
Presentation is loading. Please wait.
Published byConrad Andrews Modified over 9 years ago
1
Copyright © 2008-2014 Curt Hill PhP History and Introduction
2
Beginnings Developed by Rasmus Lerdorf Member of the Apache Group Implemented in approximately 1995 Rasmus wanted to track visitors to his home page The name is the acronym for Personal Home Page –This is a dumb name and so became: PhP: Hypertext Preprocessor Copyright © 2008-2014 Curt Hill
3
Growth Within about two years of release it was very widespread Main focus is on Server Side processing Normally used for forms processing and database access Most common server side language Is and was an open source product –http://www.php.net/http://www.php.net/ Copyright © 2008-2014 Curt Hill
4
Versions Like most languages PhP has gone through a number of versions The most recent is version 5.6 –Version 5.6.3 is current Versions 5.5 and 5.4 are still available with recent bugs fixed Version 4 is still available, but fading fast Copyright © 2008-2014 Curt Hill
5
Server Side Options There are several ways to process data at the server CGI - Common Gateway Interface ASP - Active Server Pages JSP - Java Server Pages Java Servlets Cold Fusion Server side JavaScript Clearly there is a market needing to be serviced Copyright © 2008-2014 Curt Hill
6
Server Side Processing Most of these require spawning an additional thread from the server They are routines that are outside of the server PhP is more like JavaScript –JavaScript is interpreted by the browser –PhP is interpreted by the server Server recognizes PhP by an extension such as.php.php3,.phtml Copyright © 2008-2014 Curt Hill
7
Server or Client Side We typically have one server and a myriad of clients Thus we prefer to let the client machine do as much processing as possible to ease the server workload There are some things that just cannot be done client-side, so we use PhP for this –Such as database access Copyright © 2008-2014 Curt Hill
8
PhP File Contents A PhP file must have PhP code It may also contain HTML or any type of client side script –HTML in the broadest sense: HTML or XHTML The server will either copy or interpret the file –Or both Copyright © 2008-2014 Curt Hill
9
Server Modes When the server sees HTML it merely copies this to the client –Copy mode When the server sees PhP it interprets this –Only the program output reaches the client –Interpret mode Many files have both copy and interpretation PhP is transparent –Client never sees any of it Copyright © 2008-2014 Curt Hill
10
Compilation or Interpretation? Historically PhP has always been interpreted by the server There is a performance penalty for this Types of pre-compilation have been done to speed up the script –Helpful for large and complicated scripts –Eases server workload Copyright © 2008-2014 Curt Hill
11
Language Overview PhP has much in common with both Perl and JavaScript Dynamic typing –No type declaration –Variables may change type during a program Forgiving syntax Large libraries Copyright © 2008-2014 Curt Hill
12
PhP Script Tag The script tag has following form: You may also use There may be multiple scripts in a file This tag is replaced by the program output before the client sees it –Even View Page Source will not show the PhP code Copyright © 2008-2014 Curt Hill
13
Other Tags PhP may also be enclosed in short tags or ASP tags A short tag is just the: An ASP tag is: The previous two are always enabled but these two may need mention in the initialization file of the server Copyright © 2008-2014 Curt Hill
14
Some Reserved Words Copyright © 2008-2014 Curt Hill andbreakcaseclassconst continuedeclaredefaultdoecho elseelseifextendsfalsefor foreachfunctionglobalifinclude listnewnotorprint requirereturnstaticswitchthis truevarvirtualxorwhile
15
Comments Three types Two single line comments: –# - the same as Perl –// - the same as C++/Java Multiple line comments: –Starts with /* –Ends with */ –Similar to C/C++/Java among others Copyright © 2008-2014 Curt Hill
16
Variables Variables must start with a dollar sign This must be followed by letters, underscores or digits Variables are case sensitive Reserved words are not case sensitive There is no way to declare a variable –Just use it Copyright © 2008-2014 Curt Hill
17
Stropping –Marking names with special characters PhP is unusual in that it forces variables to start with a special character, the $ This has several nice results It makes parsing easy No confusion between a variable and anything else A variable may be recognized as a variable even within a string Makes for harder typing Copyright © 2008-2014 Curt Hill
18
Types PhP has four scalar or primitive types: Boolean integer double string There are two structured types: array object Two special types: resource NULL Copyright © 2008-2014 Curt Hill
19
Statements Statements in PhP are terminated by semicolons The last one in a PhP script may be omitted The braces are used to wrap multiple statements into one like in the C family of languages There are two levels of scope –Global scope –Scope of a function body Most of the operators of Java still exist Copyright © 2008-2014 Curt Hill
20
Output There are several output statements of note print, printf and echo Today we will only consider print Form: print “Any string”; Either quote may be used print ‘Hi there.’; Copyright © 2008-2014 Curt Hill
21
Multiline Print Print may output multiple lines: print “This stuff and some more and the last.”; It will actually put out three lines with newlines (\n) in between However, if the recipient is a web browser the redundant white space (including the newline) is compacted Copyright © 2008-2014 Curt Hill
22
Printing variables Very easy Print variables directly: print $count; Variables may be recognized inside double quotes: print “The answer is: $ans”; This makes formatting output easy Copyright © 2008-2014 Curt Hill
23
include The include function inserts another file into the PhP program The form is: include(“filename”); –This file does not need the.php extension The file may be HTML, client script or PhP The server enters copy mode at the beginning of the inclusion Copyright © 2008-2014 Curt Hill
24
As Seen by the Server Copyright © 2008-2014 Curt Hill PHP Demo 1 PHP Demo Page #1 Here is the slot. <?php print " Hello World! "; ?> Return to the CIS 420 Home Page.
25
As Seen by the Browser Copyright © 2008-2014 Curt Hill PHP Demo 1 PHP Demo Page #1 Here is the slot. Hello World! Return to the CIS 420 Home Page.
26
Client View Copyright © 2008-2014 Curt Hill
27
Source Copyright © 2008-2014 Curt Hill
28
Example commentary PhP is typically inside HTML so when it does prints, it uses HTML tags All the PhP disappeared, but the output of the PhP program is retained –All the raw HTML was merely copied Copyright © 2008-2014 Curt Hill
29
phpinfo() This function will show you the characteristics of the PhP interpreter on this system It will show things like: –Operating System –PhP version –Configurations information Copyright © 2008-2014 Curt Hill
30
XML Did you notice the similarities between PhP tags and XML? If short tags are enabled this causes some problems One of which is that an XML file will be served as empty Solutions: Only use HTML - no XML header Have PhP write out the XML header Disable short tags Copyright © 2008-2014 Curt Hill
31
Example Copyright © 2008-2014 Curt Hill <?php print "<?xml... ?> <!DOCTYPE......
32
Finally PhP seems to be the most popular of the server side scripting languages –However, there is money to be made here so competition is fierce It has very good libraries for accessing databases –The SQL example pages all use PhP scripts Copyright © 2008-2014 Curt Hill
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.