Pixels Infotech: PHP Material
Pixels Infotech: PHP Material
PHP Material
1st Day
The programs present in the client machine to send a request to the server, to send data to the
server and also to get the response from server is known US client side program (Browser).
The programs present in the server machine to receive the request from the client, to process
the request and to give and appropriate response back to the client is known as server side
applications.
When a client is sending a request HTTP protocol will create an HTTP request object which
contains all the HTTP details of the client and that object will be sent to the server, their it get
process an HTTP response object gets created and that object will come to the client side.
PHP Scripts are being encoded in the server side like ASP.
Another future of PHP is PHP can work with most of the database My SQL, Oracle, SQL Server
etc.
PHP applications are platform independent that means if you develop a PHP application in one
operating system. That application you can run in any other operating system.
PHP applications can be deployed in most of the web servers like IIS, APACHE, Personal Web
Server, Samba Server etc.
A web server is an application running in the server machine capable of receiving HTTP request
every web server is identified with a specific port.
History of PHP:-
PHP 3.0 was introduced in 1998 by Andi Gutmans and Zeev Suraski.
A PHP program gets encoded in the server and will give the response back to the client in pure
HTML.
Server Side Applications – PHP parser, a web server and a browser in the client side
is required
Desktop or GUI Applications – PHP – GTK is used for developing GUI applications.
GTK stands for GIMP Tool Kit.
GIMP stands for GNU Image Manipulation Program.
3rd Day
Install IIS:-
Every web server has got a server directory where we need to place our server side programs
To check weather the server is running or not we can use a URL from the client side.
Protocol
Hostname
Port No
Resource Name in that Protocol and Hostname are mandatory.
http://localhost
http://name (pixels)
http://IP address
<html>
<body bg color= pink>
<h1> Response from IIS web server</h1>
</body>
</html>
For PHP
<? PHP
echo “<h1> Response from a PHP program in IIS</h1>
?>
To executing any server side program the corresponding handler is required in the web server.
Expand websites - Properties (Default Website Properties dialog box will be displayed).
Select “Home directory” tab from the properties dialog box click of configure button.
PHP
Data Base Server - My SQL
Web Server - APACHE
FTP Client - To Upload/Download Files
Mail Server
Remote DB Administration Tool
By a single installation all the above products should be installed in our system, for that we can
use any of the following installers.
XAMPP Installs:-
PHP
PERL
APACHE Web Server
My SQL DB Server
Mercury - Mail Server
File Zilla - FTP Client
PHP My Admin - Remote DB Administration Tool etc.
In a case of XAMPP the default server directory is C: /XAMPP/htdocs that means all the server
side programs has to be placed in htdocs folder.
Note: - click on “Port - check” button in XAMPP Control Panel to check the available ports.
Search for “Server name localhost: 80” and replace 80 with 8082.
Save the file and restart Apache Web Server; now apache is working in the port 8082.
The URL to be used is http://localhost:8082 to invoke pixels.php program we can use the
URL http://localhost:8082/pixels.php
5th Day
HTML
CSS (Case Cading Style Sheet)
JS (Java Script)
PHP Files
PHP Interfaces
PHP Classes
XML Files
Sub Directories
Images, Sound Files, Video Files etc.
The different IDES – (Integrated Development Environments) used for developing a PHP.
PHP Designer
Rapid PHP
Zend Studio
PHP Edit
PHP ED
Dream Weaver
Code Lobster
Net Beans IDE for PHP, etc.
Download and Install Net Beans IDE for PHP:-
File Menu - New Project - Select PHP from categories and select “PHP Application” from
Project - Next - Project Name: PHP Proj24 - Next - Run As : local website
As a result of the above steps a new directory gets created with the name of project
(PHP Proj24) in C:\XAMPP\htdocs folder with index.php as the default home page.
<? PHP
echo “<h1> Response from one.php”
?>
Open Browser
Provide the URL as http://localhost:8082/phpproj24/one.php
A PHP file contains HTML Tags, Plain Text, and PHP Scripts
In a PHP program server side PHP Scripts are integrated in side a mark up language – HTML
In a PHP program server side PHP Scripts should be written inside a PHP Block.
A PHP Block can be present any where in the program and any number of times
A standard PHP Block always starts with <? PHP and ends with ?>
A standard Scripting Block is understandable for any web server that supports PHP.
On servers with shorthand support a enabled you can start a scripting block with <? End with?>
And also ASP Style block which starts with <% and ends with %>
Shorthand open block and ASP Style block will be allowed by a web server only if it is configured
in php.ini
Search for the value of “short_open_tag” and “asp_tags” in php.ini file to identify whether the
web server supports short open block or asp block.
echo and Print are the language constructs of PHP used for out putting text or to give a response
back to the client
Comments in PHP:-
6th Day
<html>
<body bgcolor=”cyan”>
<h1 align = center> Pixels Infotech::: PHP Proj24 </h1>
<? PHP
echo “<h2> Response from PHP Block </h2>
print “**** </h2>”
?>
Variables in PHP:-
Variables are used for strong values like text strings, numbers or arrays.
When a variable is set it can be used over and over again in your script.
All variables in PHP starts with a “$” (Dollar Sign Symbol).
You do not have to tell PHP which data type the variable is.
PHP automatically converts the variable to the correct data type, depending on how they are set.
A PHP variable name can have alpha numeric characters and also _ (Under Score).
Dot (Pried Operator) is acting the can operator used for appending different types of data
together.
Example 1:-
<? php
echo "<h1>";
$Firstname ="Pixels";
$Lastname ="Infotech";
$_age ="3 years";
echo $Firstname."----".$Lastname."----". $_age."<br>";
echo "$Firstname----$Lastname----$_age<br>";
echo '$Firstname----$Lastname----$_age<br>';
?>
Note: - if you echo a variable in Double Quotes (“”) self expansion of the variable will happen
where the memory usage is small.
4 Scalar Types (a variable in which only one value can be stored at a time is known as scalar
type).
Boolean
Integer
Float / Double
String
2 Special Types
Resource
Null
The type of a variable is usually not set by the program; rather, it is decided at runtime by PHP
depending on the context in which that variable is used.
var_dump (variable_name) is a built in function of PHP used for getting the type of the variable
with content.
Example 2:-
<?php
echo "<h1>";
$x =10;
var_dump($x);
echo "<br>";
echo "<h1>";
$x =10.65;
var_dump($x);
echo "<br>";
echo "<h1>";
$x =Pixels;
var_dump($x);
echo "<br>";
echo "<h1>";
$x =False;
var_dump($x);
echo "<br>";
?>
7th Day
gettype (variable_name) is a built in function PHP used for getting the type of a variable.
settype (variable_name, new type) is a built in function of PHP used for setting a new type to a
variable.
unset (variable_name) is a built in function of PHP used for removing the content of a variable.
Example 3:-
<?PHP
Echo “<h1>”;
$x = ”10A”;
var_dump ($x);
echo “<br>”;
echo gettype ($x).”----”.$x. “<br>”;
unset ($x);
var_dump ($x);
echo “<br>”;
echo gettype ($x). “----“ .$x. “<br>”;
?>
<?PHP
$a = “Pixels”;
$b = “Infotech”;
$c = $a+$b;
Echo “Result =”.$c;
?>
<?PHP
$a = ?
If (gettype ($a) == “integer”)
echo “variable is of INTEGER type”;
else
echo “variable is not of INTEGER type”;
?>
is _ [type] (variable_name)
set of function including is_into (), is_double (), is_float (), is_bool (), is_string (), is_array (),
is_integer (), is_object (), etc. to check whether a specific variable matches the data type.
<?PHP
$a = “10”;
If (is_int ($a))
Echo “variable is of Integer type”;
?>
Constant Variables in PHP:-
A variable whose value can not be change at any point of time or a variable that can not be
assigned is known as a constant variable.
In PHP a constant variable should not start with $ (Dollar Sign) symbol.
PHP_OS is a pre defined built in constant of PHP used for getting the name of the operating
system in which current PHP installation is done.
PHP info ( ) is a built in function of PHP used for getting the complete configuration details about
PHP.
<?php
Define (“Name, “Pixels Infotech”);
Define (“AGE” , 13);
Define (“Name”, “Accenture”);
Echo Name. “----” . AGE, “<br>”;
Echo PHP_OS. “<br>”;
phpinfo ();
?>
<? php
echo “<h1>”;
$var1 = “12.65”;
$new int = (int) $var1;
$new float = (float) $var1;
echo $ new int. “----” $ new float
?>
With respective data types variables are classified into two types.
Value Type:-
int a = 10
int b = a
b = 20;
Reference Type:-
1. PHP Basics
1. How PHP Works
2. The php.ini File
3. Basic PHP Syntax
1. PHP Tags
2. PHP Statements and Whitespace
3. Comments
4. PHP Functions
5. Hello World!
4. Variables
1. Variable Types
2. Variable Names (Identifiers
3. Type Strength
4. Hello Variables!
5. Variable Scope
6. Superglobals
7. Constants
8. Variable-Testing and Manipulation Functions
5. First PHP Script
6. PHP Operators
7. Creating Dynamic Pages
1. Single Quotes vs. Double Quotes
2. Passing Variables on the URL
8. Passing Variables via the Query String
2. Flow Control
1. Conditional Processing
1. If Conditions
2. Working with Conditions
3. Loops
1. while
2. do...while
3. for
4. break and continue
4. Working with Loops
3. Arrays
1. Enumerated Arrays
1. Initializing Arrays
2. Appending to an Array
3. Reading from Arrays
4. Looping through Arrays
2. Working with Enumerated Arrays
3. Associative Arrays
1. Initializing Associative Arrays
2. Reading from Associative Arrays
3. Looping through Associative Arrays
4. Superglobal Arrays
4. Working with Associative Arrays
5. Two-dimensional Arrays
1. Reading from Two-dimensional Arrays
2. Looping through Two-dimensional Arrays
6. Array Manipulation Functions
4. PHP and HTML Forms
1. HTML Forms
1. How HTML Forms Work
2. A Sample HTML Form
3. Form Variables
2. Processing Form Input
5. String Manipulation
1. Formatting Strings
1. Concatenation
2. String Manipulation Functions
3. Examples of String Functions
2. Working with String Manipulation Functions
3. Magic Quotes
1. magic_quotes_gpc
2. magic_quotes_runtime
3. Recommendation on Magic Quotes