0% found this document useful (0 votes)
113 views32 pages

Introduction To PHP (Part-1) : Khizra Hanif, Department of Software Engineering, LGU Lahore, Pakistan

The document introduces PHP by discussing setting up a development environment with WAMP server, providing an overview of PHP including how it integrates with HTML and outputs to the browser, and covering PHP constants and variables including declaring and using them. It defines PHP as a server-side scripting language used to create dynamic web pages, and discusses setting up WAMP server, writing and executing PHP code, and outputting content.

Uploaded by

Muhammad Noman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views32 pages

Introduction To PHP (Part-1) : Khizra Hanif, Department of Software Engineering, LGU Lahore, Pakistan

The document introduces PHP by discussing setting up a development environment with WAMP server, providing an overview of PHP including how it integrates with HTML and outputs to the browser, and covering PHP constants and variables including declaring and using them. It defines PHP as a server-side scripting language used to create dynamic web pages, and discusses setting up WAMP server, writing and executing PHP code, and outputting content.

Uploaded by

Muhammad Noman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Introduction to PHP (Part-1)

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
Outline
• Setting the environment
• Overview of PHP
• Constants and Variables in PHP

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
1. Setting the environment
• A web server
• PHP WAMP Server
• MySql
• http://www.wampserver.com/en/
• Editor
– Macromedia Dreamweaver /Adobe
Dreamweaver
– Notepad++

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
1. Setting the environment ….
• Checking WAMP status:
WAMP is working properly

• MSVCR100.dll is missing
– Install Microsoft Visual C++ 2010 SP1
Redistributable Package
• Port conflict with skype
Khizra Hanif, Department of Software
Engineering, LGU Lahore, Pakistan.
2. PHP: an Overview
• PHP: Hypertext Preprocessor
• Originally called “Personal Home Page Tools”
• Used to create dynamic web pages
• Popular server-side scripting technology
• Open-source
– Anyone may view, modify and redistribute
source code
• Platform independent
Khizra Hanif, Department of Software
Engineering, LGU Lahore, Pakistan.
2. PHP: an Overview…
• Interpreted language, scripts are parsed at
run-time rather than compiled beforehand
• Compatible with many popular databases
• Popular server-side scripting technology
• Structurally similar to C/C++
• Supports procedural and object-oriented
paradigm

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2. PHP: an Overview…

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.1 How PHP Fits with HTML
• Embedding PHP in HTML code
• HTML can also be written inside the PHP code
• PHP can also be written as a standalone program
with no HTML at all

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.2 Basic Rules of PHP syntax
• PHP code is denoted in the page with opening
and closing tags, as follows:
– <?php and ?>
– <? or ?>
– <script language=“PHP”>…… </script>
• PHP statements end with a semicolon
• Comments can be added as
– // for one line comment
– /* and */ for multiple lines comment

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.3 Writing and executing PHP code
• Open a notepad or dreamweaver file
• Write PHP code
• Save file with .php extension
• Save all the files in one directory
• Copy this directory in
– C:\wamp\www\

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.3 Writing and executing PHP code…
• Start WAMP server
• Go to localhost either by typing localhost in
address bar of the browser or by clicking the
WAMP sever icon in the toolbar and selecting
localhost
• Select your web directory from the list of project
on the WAMP server home page
• Select the file to execute

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.4 Writing output to the browser
• echo(): is used to write output on the browser
– echo(“Welcome to PHP”);
– echo “Welcome to PHP”;
• print(): can also be used to write out put on the
browser
– print(“Welcome to PHP”);
– print “Welcome to PHP”;
• printf(): can also be used for writing output

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.5 First PHP program

PHP block starts

Writing on browser
Ending PHP
block

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.5 First PHP program…

Out put from the


PHP code

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.6 Integrating HTML with PHP
• echo statement outputs whatever it’s told to
the browser
• It can output not only plain text but also
HTML tags
– echo “<h1> Welcome to the PHP</h1>”;

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.6 Integrating HTML with PHP…
• Using quotation marks:

– echo “<h1 style=“color:red”> Welcome to PHP</h1>”;

– echo “<h1 style=‘color:red’> Welcome to PHP</h1>”;

– echo “<h1 style=\“color:red\”> Welcome to


PHP</h1>”;

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.6 Integrating HTML with PHP…

Using heading Arranging


quotations

Using escape character

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.6 Integrating HTML with PHP…

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3. Using CONSTANS and
Variables

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3.1 CONSTANTS
• A constant is a placeholder for a value that you
reference within your code that is formally
defined before using it
• must begin with a letter or an underscore
• are case sensitive
• typically they are named using all capital letters
• PHP function define() is used to assign a value to
a constant

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3.1 CONSTANTS…

Constant name Value of


constant

Displaying the value

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3.2 Variables
• Begin with $ sign
• First character must be a letter or underscore
• Remaining characters may be letters, numbers or
underscores
• Don’t need to declare or initialize
• Case sensitive
• Data types does not require to be declare explicitly
• Supports
– Float, integer, boolean, string, array, object

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3.2 Variables…

Variable
declared
Initial value

Displaying variable’s value

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3.2 Variables…

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3.2 variables…
• The gettype() function returns the type of the
provided variable
• The settype() function converts a variable to
the type specified by type

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
3.2 Variables…

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.2 Variables…

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.2.1 Type determination
• A number of functions are available for determining a
variable’s type
– boolean is_name(mixed var)
• is_array()
• is_bool()
• is_float()
• is_integer()
• is_null()
• is_numeric()
• is_string()
Khizra Hanif, Department of Software
Engineering, LGU Lahore, Pakistan.
2.2.1 Type determination…

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
2.2.1 Type determination…

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
Summary
• Setting the environment
• PHP overview
• PHP constants and variables

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.
References
• Chapter 2, “Beginning PHP6,Apache,Mysql
web development” by Matt Doyle, Wrox
publishers, 2009, ISBN: 0470413964
• Chapter 3, “Beginning PHP and MySQL” by W.
Jason Gilmore, Apress publisher, 4th edition;
2010, ISBN-13 (electronic): 978-1-4302-3115-
8.

Khizra Hanif, Department of Software


Engineering, LGU Lahore, Pakistan.

You might also like