php php: hypertext preprocessing matt murphy & dublas portillo
TRANSCRIPT
PHPPHPPHP: Hypertext PreprocessingPHP: Hypertext Preprocessing
Matt Murphy & Dublas PortilloMatt Murphy & Dublas Portillo
What is PHP?What is PHP? PHP is a server-side scripting language PHP is a server-side scripting language
designed specifically for the Web.designed specifically for the Web. An open source languageAn open source language PHP code can be embedded within an PHP code can be embedded within an
HTML page, which will be executed each HTML page, which will be executed each time that page is visited.time that page is visited.
Example code (all equivalent):Example code (all equivalent): Short StyleShort Style: : <? echo “Hello World!”; ?><? echo “Hello World!”; ?> XML StyleXML Style: : <?php echo “Hello World!”; ?><?php echo “Hello World!”; ?> Script StyleScript Style: : <SCRIPT LANGUAGE=‘php’> echo <SCRIPT LANGUAGE=‘php’> echo
“Hello World!”; </SCRIPT>“Hello World!”; </SCRIPT> ASP StyleASP Style: : <% echo “Hello World!”; %><% echo “Hello World!”; %>
History of PHPHistory of PHP
Created by Rasmus Lerdorf in 1994Created by Rasmus Lerdorf in 1994 Originally a set of Perl scripts used by Originally a set of Perl scripts used by
Lerdorf to show off his résumé as well Lerdorf to show off his résumé as well as collect information on his website, as collect information on his website, such as the site’s traffic info.such as the site’s traffic info.
Lerdorf later transcribed these Perl Lerdorf later transcribed these Perl scripts into a set of CGI binaries scripts into a set of CGI binaries written in C, and in doing so, written in C, and in doing so, combined it with his own Form combined it with his own Form Interpreter to create PHP/FI.Interpreter to create PHP/FI.
History of PHPHistory of PHP
PHP/FI grew in popularity, but did not PHP/FI grew in popularity, but did not become widely known until two become widely known until two program developers named Zeev program developers named Zeev Suraski and Andi Gutmans, developed a Suraski and Andi Gutmans, developed a new parser in the summer of 1997, new parser in the summer of 1997, which led to the development of PHP which led to the development of PHP 3.0.3.0.
The newest version out is PHP 5, which The newest version out is PHP 5, which uses an engine developed by Suraski uses an engine developed by Suraski and Gutmans, known as the Zend II and Gutmans, known as the Zend II Engine. (Zend I was used by PHP 4) Engine. (Zend I was used by PHP 4)
PHP Programming PHP Programming ParadigmsParadigms
Uses both procedural and object Uses both procedural and object oriented paradigmsoriented paradigms
Procedural PHPProcedural PHP Has been in use since the creation of PHP, Has been in use since the creation of PHP,
its primary paradigm.its primary paradigm. Allows for easy and quick learning of the Allows for easy and quick learning of the
PHP language.PHP language. Similar to other popular languages such as Similar to other popular languages such as
Visual Basic, C++, and Fortran.Visual Basic, C++, and Fortran.
PHP Programming PHP Programming ParadigmsParadigms
Object Oriented PHPObject Oriented PHP Similar to Java, example of an object class:Similar to Java, example of an object class:
<?php<?php
class BaseClass {class BaseClass {
function __construct() {function __construct() {
echo "In BaseClass constructor<br>";echo "In BaseClass constructor<br>";
}}
}}
class SubClass extends BaseClass {class SubClass extends BaseClass {
function __construct() {function __construct() {
parent::__construct();parent::__construct();
echo "In SubClass constructor<br>";echo "In SubClass constructor<br>";
}}
}}
$obj = new BaseClass();$obj = new BaseClass();
$obj = new SubClass();$obj = new SubClass();
?> ?>
public class BaseClass {public class BaseClass {
public BaseClass() {public BaseClass() {
System.out.println("In BaseClass constructor\System.out.println("In BaseClass constructor\n");n");
}}
}}
class SubClass extends BaseClass {class SubClass extends BaseClass {
public SubClass() {public SubClass() {
super();super();
System.out.println("In SubClass constructor\n");System.out.println("In SubClass constructor\n");
}}
}}
----------------------------------------------------------------------------------
public class Output {public class Output {
public static void main(String[] args) {public static void main(String[] args) {
Object obj;Object obj;
obj = new BaseClass();obj = new BaseClass();
obj = new SubClass();obj = new SubClass();
}}
}}
Features of PHPFeatures of PHP Very Efficient Very Efficient – Can serve millions of hits per day.– Can serve millions of hits per day.
Database Integration Database Integration – Supports many databases, such – Supports many databases, such as mySQL and Oracle. Also has excellent XML support as of as mySQL and Oracle. Also has excellent XML support as of PHP 5.PHP 5.
Built-in Libraries – Built-in Libraries – Tailored to web development, one Tailored to web development, one can connect to other network services, send email, work with can connect to other network services, send email, work with cookies, generate PDF documents, and make GIF images on the cookies, generate PDF documents, and make GIF images on the fly all with a few lines of code.fly all with a few lines of code.
It’s Free It’s Free – Available on http://www.php.net– Available on http://www.php.net
Easy to Learn Easy to Learn – Very similar in syntax to C/C++/Java and – Very similar in syntax to C/C++/Java and Perl.Perl.
Portable Portable – Works on Unix based operating systems, on Mac – Works on Unix based operating systems, on Mac OS X, as well as on versions of Microsoft Windows. Your PHP OS X, as well as on versions of Microsoft Windows. Your PHP code will often work without modification on a different system code will often work without modification on a different system running PHP. running PHP.
Database SupportDatabase Support
The following is a list of supported The following is a list of supported databases in PHP 5:databases in PHP 5:
Adabas D Adabas D InterBase InterBase PostgreSQL PostgreSQL dBase dBase
FrontBase FrontBase SQLite SQLite
Empress Empress
mSQL mSQL
FileProFilePro (read- (read-only)only)
SolidSolid
Direct MS-Direct MS-SQLSQL
SybaseSybase
HyperwaveHyperwave
MySQLMySQL
VelocisVelocis
ODBCODBC
Unix dbmUnix dbm
InformixInformixOracle Oracle (OCI7 and (OCI7 and OCI8)OCI8)
IngresIngres
OvrimosOvrimos
IBM DB2IBM DB2
Differences From JavaDifferences From Java Data types are not required in variable Data types are not required in variable
declarations.declarations. The $ symbol precedes all variables in The $ symbol precedes all variables in
PHPPHP Constants are declared using the define() Constants are declared using the define()
method in PHP: ex. method in PHP: ex. define(“AOL", "something");define(“AOL", "something"); Constructors do not necessarily have to be Constructors do not necessarily have to be
the same name as the class name.the same name as the class name. Destructors are used in PHP to remove Destructors are used in PHP to remove
objects from memory after they are objects from memory after they are constructed.constructed.
What is PHP Good For?What is PHP Good For?
It is great for complex web page designsIt is great for complex web page designs E-commerce sites with heavy traffic (ex. E-commerce sites with heavy traffic (ex.
Amazon)Amazon) Complex bulletin boards and forums (ex. Complex bulletin boards and forums (ex.
phpBB)phpBB) Secure websites (ex. Novasis)Secure websites (ex. Novasis) Email web hosts (ex. Gmail) Working with and integrating XML into your Working with and integrating XML into your
webpagewebpage Database management and search (ex. Database management and search (ex.
theFaceBook)theFaceBook)
Processing a PHP PageProcessing a PHP Page
Getting StartedGetting Started Download Apache 2 Windows Binary (MSI Download Apache 2 Windows Binary (MSI
installer) at installer) at http://httpd.apache.org/download.cgihttp://httpd.apache.org/download.cgi The zip must end with win32-x86-no_ssl.msiThe zip must end with win32-x86-no_ssl.msi
Download the PHP zip package at Download the PHP zip package at http://www.php.net/downloads.phphttp://www.php.net/downloads.php Download the zip pack, not the installerDownload the zip pack, not the installer
Install Apache 2, Install Apache 2, useuse recommended settings recommended settings If error message is given, go here (Google port 80 If error message is given, go here (Google port 80
problem): problem): http://httpd.apache.org/docs/2.0/platform/windows.http://httpd.apache.org/docs/2.0/platform/windows.htmlhtml
Unzip PHP file to C:\PHPUnzip PHP file to C:\PHP
Getting StartedGetting Started Next, copy/paste "php.ini-dist" to Next, copy/paste "php.ini-dist" to
C:/Program Files/Apache Group/Apache2, C:/Program Files/Apache Group/Apache2, and rename it to php.ini. and rename it to php.ini.
Copy the following list of .dll files from your Copy the following list of .dll files from your C:\PHP and C:\PHP\ext directory to your C:\PHP and C:\PHP\ext directory to your root Apache directory (where you put root Apache directory (where you put php.ini):php.ini): fdftk.dll fribidi.dll gds32.dll libeay32.dll fdftk.dll fribidi.dll gds32.dll libeay32.dll
libmash.dll libmysql.dll libmysqli.dll msql.dll libmash.dll libmysql.dll libmysqli.dll msql.dll ntwdblib.dll php5apache2.dll php5apache.dll ntwdblib.dll php5apache2.dll php5apache.dll php5apache_hooks.dll php5isapi.dll php5nsapi.dll php5apache_hooks.dll php5isapi.dll php5nsapi.dll php5ts.dll phpmsql.dll phpmssql.dll phpmysql.dll php5ts.dll phpmsql.dll phpmssql.dll phpmysql.dll phpmysqli.dll ssleay32.dll yas.dll phpmysqli.dll ssleay32.dll yas.dll
Getting StartedGetting Started Set the PHP path for Windows: Set the PHP path for Windows:
Go to: Go to: Control Panel > System > Advanced tab Control Panel > System > Advanced tab Click on "Environment variables" Click on "Environment variables" Look in the "System variables" pane Look in the "System variables" pane Find the "Path" entry Find the "Path" entry Double click it and add at the end of the string your PHP dir Double click it and add at the end of the string your PHP dir You need to start with ";" without double quotes! You need to start with ";" without double quotes! And follow by: C:php And follow by: C:php So it will look like: ";C:php" Again, without double quotes! So it will look like: ";C:php" Again, without double quotes! Now restart the Apache server. Now restart the Apache server. Test: Create a simple file (using notepad) such as php5_info.php Test: Create a simple file (using notepad) such as php5_info.php <? phpinfo();?> <? phpinfo();?>
Save it in C:/Program Files/Apache Save it in C:/Program Files/Apache Group/Apache2/htdocs/php5_info.php Group/Apache2/htdocs/php5_info.php Open a browser and enter the following address Open a browser and enter the following address http://localhost/php5_info.phphttp://localhost/php5_info.php it should display your complete it should display your complete PHP setting if it does not work properly you might have done PHP setting if it does not work properly you might have done something wrong with the multiple edits; check them out and something wrong with the multiple edits; check them out and give it another go.give it another go.
Now you can use any text editor or html editor to create PHP Now you can use any text editor or html editor to create PHP filesfiles
An ExampleAn Example
titleCreator.phptitleCreator.php Uses a simple form with simple fieldsUses a simple form with simple fields Asks a user for input, such as the title Asks a user for input, such as the title
they want, what their name is, the they want, what their name is, the background color, etc.background color, etc.
When submitted, the page is reloaded When submitted, the page is reloaded with the specified form values using with the specified form values using PHP code to write out new HTML codePHP code to write out new HTML code
titleCreator.phptitleCreator.php
Useful LinksUseful Links
Official Website (Official Website (http://www.php.net/http://www.php.net/)) PHP Online Manual PHP Online Manual
((http://us2.php.net/manual/en/http://us2.php.net/manual/en/)) Installation on Windows Systems Installation on Windows Systems
((http://us2.php.net/manual/en/install.windows.phphttp://us2.php.net/manual/en/install.windows.php)) Using Apache with Windows Using Apache with Windows
((http://httpd.apache.org/docs/2.0/platform/windows.htmlhttp://httpd.apache.org/docs/2.0/platform/windows.html
)) Alternative Installation Guide Alternative Installation Guide
((http://www.webmasterstop.com/86.htmlhttp://www.webmasterstop.com/86.html))