Adet Modules For Fa1
Adet Modules For Fa1
Adet Modules For Fa1
What is PHP?
• PHP is an acronym for "PHP: Hypertext Preprocessor"
• PHP is a widely-used, open source scripting language
• PHP scripts are executed on the server
• PHP is free to download and use
Why PHP?
• PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
• PHP is compatible with almost all servers used today (Apache, IIS, etc.)
• PHP supports a wide range of databases
• PHP is free. Download it from the official PHP resource: www.php.net
• PHP is easy to learn and runs efficiently on the server side
Introduction to PHP
PHP is one of the most widely used server-side scripting language for web development. Popular websites
like Facebook, Yahoo, Wikipedia etc., and our very own Study tonight, are developed using PHP.
PHP is so popular because it's very simple to learn, code and deploy on server, hence it has been the first
choice for beginners since decades.
In this tutorial series we will be covering all the important concepts of Php language from basics to
advanced and will also share some ready-to-use, useful code snippets for beginners to kickstart their web
development project.
What is PHP?
PHP stands for Hypertext Pre-Processor. PHP is a scripting language used to develop static and dynamic
webpages and web applications. Here are a few important things you must know about PHP:
1. PHP is open source and free, hence you can freely download, install and start developing using it.
2. PHP has a very simple and easy to understand syntax, hence the learning curve is smaller as
3. PHP is cross platform, hence you can easily develop and move/deploy your PHP code/project to
almost all the major operating systems like Windows, Linux, Mac OSX etc.
4. All the popular web hosting services support PHP. Also the web hosting plans for PHP are
5. Popular Content Management Systems like Joomla, Drupal etc. are developed in PHP and if you
want to start your own website like Study tonight, you can easily do that with PHP.
6. With PHP, you can create static and dynamic webpages, perform file handling operations, send
emails, access and modify browser cookies, and almost everything else that you might want to
7. PHP is fast as compared to other scripting languages like JSP and ASP.
8. PHP has in-built support for MySQL, which is one of the most widely used Database management
system.
These are some of the main features of PHP, while as you will learn the language you will realize that apart
from these features,
Uses of PHP
To further fortify your trust in PHP, here are a few applications of this amazing scripting language:
2. Command Line Scripting. You can write PHP scripts to perform different operations on any
3. Create Facebook applications and easily integrate Facebook plugins in your website, using
4. Sending Emails or building email applications because PHP provides with a robust email sending
function.
5. Wordpress is one of the most used blogging (CMS) platform in the World, and if you know PHP,
PHP started out as a small open source project that evolved as more and more people found out how
useful it was. Rasmus Lerdorf unleashed the first version of PHP way back in 1994.
• PHP is a recursive acronym for "PHP: Hypertext Preprocessor".
• PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic
content, databases, session tracking, even build entire e-commerce sites.
• PHP is pleasingly zippy in its execution, especially when compiled as an Apache module on the
Unix side. The MySQL server, once started, executes even very complex queries with huge result
sets in record-setting time.
• PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. PHP4 added
support for Java and distributed object architectures (COM and CORBA), making n-tier
development a possibility for the first time.
• PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data,
return data to the user.
• You add, delete, modify elements within your database thru PHP.
• Using PHP, you can restrict users to access some pages of your website.
Characteristics of PHP
Five important characteristics make PHP's practical nature possible:
• Simplicity
• Efficiency
• Security
• Flexibility
• Familiarity
PHP in the Web Environment
PHP programs are written using a text editor, such as Notepad, Simple Text, or vi, just like
HTML pages. However, unlike HTML, PHP files end with a .php extension. This extension
signifies to the server that it needs to parse the PHP code before sending the resulting HTML
code to the viewer’s web browser. In PHP, on the fly method is adopted to publish the
document. Hence, the PHP developer can generate not only web pages, but also other web
embedding documents like PDF, PNG, GIF, etc. The PHP web environment is usually set
with AMP (Apache, MySQL, and PHP/Perl/Python), which are linked together.
HTML can also be written inside the PHP code of your page, which allows you to format text
while keeping blocks of code together. This will also help you write organized, efficient
code, and the browser (and, more importantly, the person viewing the site) won’t know the
difference.
PHP can also be written as a standalone program with no HTML at all. This is helpful for
storing your connection variables, redirecting your visitors to another page of your site, or
performing other functions.
1
PHP in the Web Environment
o Hostname: In our case, this is localhost because everything has been installed locally.
You will need to change this to whatever host is acting as your MySQL server, if MySQL
is not on the same server.
o Username and password: This is to authenticate securely over server end.
You issue this connection command with the PHP function called mysql_connect(). As
with all of your PHP/MySQL statements, you can either put the information into variables or
leave it as text in your MySQL query.
For the most part, your specific needs and the way you are designing your table will dictate
what piece of code you use. Most people use the first method for security ‘sake and put the
variables in a different file. Then they include them wherever they need to make a connection
to the database.
1. Web interface
2. MySQL database management
3. Import data from CSV and SQL
4. Export data to various formats: CSV, SQL, XML, PDF (via the TCPDF library), ISO/IEC
26300 - OpenDocument Text and Spreadsheet, Word, Excel, LaTeX and others
2
PHP in the Web Environment
AMP Bundles
There are many AMP bundles such as LAMP, XAMP, PHPTriad, WAMP, MAMP, FoxServ,
etc. consists of AMP build in itself. So, there is no need to configure AMPs manually. Some
of the AMPs which are available for various operating systems are LAMP (for Linux);
WAMP (for Windows); MAMP (for Macintosh); SAMP (for Solaris); and FAMP (for
FreeBSD).
3
PHP - Environment Setup
In order to develop and run PHP Web pages three vital components need to be installed on your
computer system.
• Web Server − PHP will work with virtually all Web Server software, including Microsoft's Internet
Information Server (IIS) but then most often used is freely available Apache Server. Download
Apache for free here − https://httpd.apache.org/download.cgi
• Database − PHP will work with virtually all database software, including Oracle and Sybase but
most commonly used is freely available MySQL database. Download MySQL for free here −
https://www.mysql.com/downloads/
• PHP Parser − In order to process PHP script instructions a parser must be installed to generate
HTML output that can be sent to the Web Browser. This tutorial will guide you how to install
PHP parser on your computer.
Step1:
Download the XAMPP server click on above link.
Step 2:
Install the exe file which is downloaded.
Step 3:
Now to go C drive (or where you install the server) and open XAMPP folder
and find XAMPP control file and double click on that.
Step 4:
Click on start button on Apache and MYSQL both.
Step 5:
Now open web browser like Google chrome and type "localhost" and check
XAMPP server welcome page is appeared or not. If appeared then our server
is started.
Now create your own folder under htdocs , Example name it as test or what
ever.
Step 6:
Now write your first PHP code and name it as “index.php” and save it under
test folder.
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello World!";
?>
</body>
</html>
Step 7:
Now open your web browser and type localhost/test/index.php.
Applications Development and
Emerging Technologies
MODULE 1
Web Architecture, Tools, and
Introduction to PHP
An introduction to PHP web programming
Objectives
• To understand the history of PHP
• To know the advantages of PHP as a server side scripting
language
• To know what are the software's needed in developing web
application using PHP.
• To run PHP application on a web browser.
• To know the basic syntax of PHP for outputting to browser.
• To know the datatypes that are available on PHP and on
how these datatypes are being used.
• To know some predefined type function for data
manipulation.
• To know the proper casting values of a given variables.
An introduction to PHP web programming
HISTORY
• 1994/1995 (PHP 1.0)
• Developed by Rasmus Lerdorf
• To know how many visitors were reading his online
resume based on PERL/CGI script
• Personal Home Page (PHP)
• 1997 (PHP 2.0)
• PHP is based on C rather than PERL
• Personal Home Page/Form Interpreter
• 1998 (PHP 3.0)
• 50,000 users were using PHP to enhance their Web pages
• Developers joined Lerdorf
• 1999 (PHP 4.0)
• With core developers Zeev Suraski and Andi Gutmans
• PHP makes the most popular scripting language with
morethan one million user base by Netcraff
An introduction to PHP web programming
HISTORY (Con’t.)
• Hundreds of functions being added
• Dubbed the Zend scripting engine
• May 22, 2000 (PHP 4.0)
• PHP: Hypertext Preprocessor (recursive acronym)
• 3.6 million domain PHP installed
• Enterprise development
• Improved resource handling (scalability)
• Object-oriented support (Classes and Objects)
• Native session-handling support (session)
• Encryption (encryption algoritms)
• ISAPI Support (for IIS)
• Native COM/DOM (Windows applications)
• Native Java Support: (binding to java objects)
• PERL Compatible Regular Expressions
• New features, power, and scalabilty
An introduction to PHP web programming
HISTORY (Con’t.)
• PHP 5 (July 13, 2004)
• Vastly improved object-oriented capabilities: OOP
improvement
• Try/catch exception handling
• Improved XML and Web Services support (Simple XML
Support, using SOAP)
• Native support for SQLite
• Installed on 19 million domains
• 54 percent on all Apache module
• PHP 6 (2007 not yet released)
• Unicode Support (Native Unicode support for multilingual
applications
• Security improvements
• New language features and constructs (64-bit type integer,
foreach looping)
http://en.wikipedia.org/wiki/PHP
An introduction to PHP web programming
HISTORY (Con’t.)
PHP Key categories
• Practicality
• PHP is a loosely type language (no explicitly create,
typecast, or destroy a variable)
• Power
• More libraries and thousands of functions
• Possibility
• Native support is offered for more than 25 database
products, including Adabas D, dBase, Empress,
FilePro, FrontBase, Hyperwave, IBM DB2, Informix,
Ingres, InterBase, mSQL, Microsoft SQL Server,
MySQL, Oracle, Ovrimos, PostgreSQL, Solid, Sybase,
Unix dbm, and Velocis.
• Both structured and Object Oriented approach
• Price
• Free of charge
An introduction to PHP web programming
html
Internet
scripts
database
An introduction to PHP web programming
Software Requirements
Operating System: Linux
An introduction to PHP web programming
Software Requirements
Operating System: Windows
An introduction to PHP web programming
Software Requirements
Operating System: Mac
Cheetah
Panther
Puma
Jaguar Tiger
Software Requirements
Internet browser
Opera
Mozilla
Internet Safari
Google Firefox
Chrome Explorer
Deepnet
Rockmelt Explorer Avant
Maxthon Browser
SeaMonkey
An introduction to PHP web programming
Software Requirements
Web Server
Apache
Software Requirements
Server side scripting language
Python
PERL CGI
(Django)
An introduction to PHP web programming
Software Requirements
Database
Oracle
An introduction to PHP web programming
Software Requirements
Code editor
Bluefish
Dreamweaver
An introduction to PHP web programming
Software Requirements
Other
An introduction to PHP web programming
Software Requirements
Other
Operating System
Windows 7 / Windows 8
Web Server
Apache
Database
MySQL
Code Editor
Notepad++ / Eclipse / Netbeans / Dreamweaver
An introduction to PHP web programming
OUTPUT:
An introduction to PHP web programming
PHP Comments
An introduction to PHP web programming
PHP Variables
• Variables are used as a container for values that can be used and
manipulate PHP scripts.
• Variables in PHP must begin with a $ symbol.
• Variable might contain a string, numbers, arrays and objects.
• Setting the identifier for a variable must follow some rules.
1. First character can be ‘_’ or a letter.
2. It can only contain alpha-numeric characters and underscore
(a-z,A-Z,0-9,_).
3. Don’t use white space in naming a variable.
• Variables in PHP is not explicitly declared
• Variables are case sensitive
Example
$age, $firstName, $totalSalary, $_myValue,
$str1, $tmp01
An introduction to PHP web programming
Outputting Data
echo syntax
void echo(string argument1[,…string argumentN]
print syntax
int print(argument)
printf syntax
boolean printf(string format [, mixed args])
An introduction to PHP web programming
Outputting Data
Example:
Output:
An introduction to PHP web programming
Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.100
An introduction to PHP web programming
PHP Datatypes
Datatypes
is the generic name assigned to any data sharing a common set of
characteristics.
Scalar Datatypes
Capable of containing a single item of information
(Boolean, Integer, Float (float, double or real numbers), String)
Compound Datatypes
allow for multiple items of the same type to be aggregated under a
single representative entity.
(Array and Objects)
An introduction to PHP web programming
Scalar Datatypes
Eample:
An introduction to PHP web programming
Compound Datatypes
Example:
Output:
Output:
An introduction to PHP web programming
Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.105
An introduction to PHP web programming
Example: Output:
An introduction to PHP web programming
Example: Output:
An introduction to PHP web programming
settype() function
converts a given variable to a specific type.
prototype:
boolean settype(mixed var, string type)
Type Functions
Example:
Output:
An introduction to PHP web programming
Summary
• PHP was developed originally by Rasmus Lerdorf
• Seev Suraski and Andi Gutsman were the one who contribute most
in PHP development.
• PHP key categories are practicality, power, possibility, and price.
• PHP is a embedded language that is commonly embedded on
HTML
• PHP is a server-side scripting language that runs its application on a
Web server.
• Much of the PHP syntax were derive from C programming
Language.
• You can integrate database easily in PHP.
• Standard PHP script are enclosed by <?php and ?> tags.
• Each statement in PHP must be terminated with a semi-colon(;).
• All variable in PHP must have a dollar ($) character before its
identifier.
An introduction to PHP web programming
Summary (Continue)
• PHP variables are not explicitly declared.
• You can use echo, print, or printf function for outputting strings to
internet browser.
• You can enclosed string using a pair of single quote or pair of
double quote.
• String inside a pair of single quote interpreted as literal except for
the single quote itself.
• String inside a pair of double quote interpreted as literal with some
exception like using dollar character.
• To explicitly display the character on the internet browser use
backslash (\) character like \$, \’, \” and etc.
• Datatypes in PHP can be categorized as scalar or compound
datatypes.
• You can explicitly change the type of a variable in PHP.
• PHP support some predefined type function that can be used in
manipulating type variables.
HISTORY
• Practicality
o PHP is a loosely type language (no explicitly create, typecast, or destroy a variable)
• Power
o More libraries and thousands of functions
• Possibility
o Native support is offered for more than 25 database products, including Adabas D,
dBase, Empress, FilePro , FrontBase , Hyperwave , IBM DB2, Informix, Ingres, InterBase ,
mSQL , Microsoft SQL Server, MySQL, Oracle, Ovrimos , PostgreSQL, Solid, Sybase, Unix
dbm , and Velocis Both structured and Object Oriented approach
• Price
o Free of charge
• Ubuntu
• Debian
• Linux
• Suse
• Fedora
• Kubuntu
• Centos
• Windows XP
• Windows Me
• Windows Server 2008
• Windows 7
• Windows 8
• Windows 2000
• Cheetah
• Puma
• Jaguar
• Leopard
• Snow Leopard
• Panther
• Tiger
• Lion
• Google Chrome
• Mozilla Firefox
• Internet Explorer
• Opera
• Safari
• Maxthon
• Rockmelt
• SeaMonkey
• Deepnet Explorer
• Avant Browser
• Apache
• IIS7 (Internet Information Services)
• NGINX
• Google Web Server
• Java
• Python
• Ruby
• ASP (Active Server Pages)
• PERL CGI
• PHP
• IBMDB2
• SQLite
• Postgre
• MySQL
• SQL Server
• Oracle
• Aptana
• Eclipse
• Bluefish
• Dreamweaver
• Notepad++
• Netbeans
• HTML
• CCS
• AJAX
• JavaScript
• JQuery
….
</script>(script tag)
PHP comments
/* Multiline comment */
PHP Variables
PHP Variables
•Variables are used as a container for values that can be used and manipulate PHP scripts.
Example
Using ‘ ‘ (pair single quote), “ “ (pair double quotes) and . (dot character) PHP
1.To display a ‘ character (single quote) as string use the escape character \(backslash).
2.Strings inside the “ and “ are interpreted as literal strings with some exceptions
1.$ inside “ and “ are interpreted as variables thus it will display the value rather than the string that
starts with $.
2.To display the string that starts with $ and to display the double quote as string use the escape
character \(backslash).
3.To concatenate string values use the . (dot or period) character thus “abc“.”def” yields to a value
“abcdef”
Outputting Data
echo syntax
print syntax
int print(argument)
printf syntax
Boolean printf (string format [, mixed args])
PHP Datatypes
Datatypes
is the generic name assigned to any data sharing a common set of characteristics.
Scalar Datatypes
Compound Datatypes
allow for multiple items of the same type to be aggregated under a single representative entity.
gettype()function
returns the type of the variable. Possible return values are integer, double, boolean, string, array, object,
resource, unknown types.
prototype:
settype()function
prototype:
Objectives
• To run PHP application on a web browser.
• To know the basic syntax of PHP for outputting to browser.
• To know the datatypes that are available on PHP and on
how these datatypes are being used.
• To know some predefined type function for data
manipulation.
• To know the proper casting values of a given variables.
An introduction to PHP web programming
OUTPUT:
An introduction to PHP web programming
PHP Comments
An introduction to PHP web programming
PHP Variables
• Variables are used as a container for values that can be used and
manipulate PHP scripts.
• Variables in PHP must begin with a $ symbol.
• Variable might contain a string, numbers, arrays and objects.
• Setting the identifier for a variable must follow some rules.
1. First character can be ‘_’ or a letter.
2. It can only contain alpha-numeric characters and underscore
(a-z,A-Z,0-9,_).
3. Don’t use white space in naming a variable.
• Variables in PHP is not explicitly declared
• Variables are case sensitive
Example
$age, $firstName, $totalSalary, $_myValue,
$str1, $tmp01
An introduction to PHP web programming
Outputting Data
echo syntax
void echo(string argument1[,…string argumentN])
print syntax
int print(argument)
printf syntax
boolean printf(string format [, mixed args])
An introduction to PHP web programming
Outputting Data
Example:
Output:
An introduction to PHP web programming
Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.100
An introduction to PHP web programming
PHP Datatypes
Datatypes
is the generic name assigned to any data sharing a common set of
characteristics.
Scalar Datatypes
Capable of containing a single item of information
(Boolean, Integer, Float (float, double or real numbers), String)
Compound Datatypes
allow for multiple items of the same type to be aggregated under a
single representative entity.
(Array and Objects)
An introduction to PHP web programming
Scalar Datatypes
Example:
An introduction to PHP web programming
Compound Datatypes
Example:
Output:
Output:
An introduction to PHP web programming
Beginning PHP and MySQL 3rd Edition by: W. Jason Gilmore pp.105
An introduction to PHP web programming
Example: Output:
An introduction to PHP web programming
Example: Output:
An introduction to PHP web programming
settype() function
converts a given variable to a specific type.
prototype:
boolean settype(mixed var, string type)
Type Functions
Example:
Output:
An introduction to PHP web programming
Summary
• You can integrate database easily in PHP.
• Standard PHP script are enclosed by <?php and ?> tags.
• Each statement in PHP must be terminated with a semi-colon(;).
• All variable in PHP must have a dollar ($) character before its
identifier.
• PHP variables are not explicitly declared.
• You can use echo, print, or printf function for outputting strings to
internet browser.
• You can enclosed string using a pair of single quote or pair of
double quote.
• String inside a pair of single quote interpreted as literal except for
the single quote itself.
An introduction to PHP web programming
Summary (Continue)
• String inside a pair of double quote interpreted as literal with some
exception like using dollar character.
• To explicitly display the character on the internet browser use
backslash (\) character like \$, \’, \” and etc.
• Datatypes in PHP can be categorized as scalar or compound
datatypes.
• You can explicitly change the type of a variable in PHP.
• PHP support some predefined type function that can be used in
manipulating type variables.