SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
Introduction to PHP
1
Introduction to PHP
AIMS BBSYDP TRAINING
JUNAID NAZIR
junaid@comelearnshare.com
Introduction to PHP
Introduction to PHP
• PHP is a server-side scripting language designed
for web development but also used as a general-
purpose programming language. As of January 2013,
PHP was installed on more than 240
million websites (39% of those sampled) and 2.1
million web servers.[Originally created by Ramses
Lerdorf in 1994,the reference implementation of PHP
is now produced by The PHP Group. While PHP
originally stood for Personal Home Page, it now
stands for PHP: Hypertext Preprocessor, a
recursive backronym.
• 2
Introduction to PHP
Introduction to PHP
• PHP code can be simply mixed with HTML code, or it can be
used in combination with various templating engines and web
frameworks. PHP code is usually processed by a
PHP interpreter, which is usually implemented as a web server's
native module or aCommon Gateway Interface (CGI)
executable. After the PHP code is interpreted and executed, the
web server sends resulting output to its client, usually in form of
a part of the generated web page – for example, PHP code can
generate a web page's HTML code, an image, or some other
data. PHP has also evolved to include a command-line
interface (CLI) capability and can be used
in standalonegraphical applications.
•
3
Introduction to PHP
4
Introduction to PHP
• PHP Hypertext Preprocessor.
– Other Names : Personal Home Page, Professional Home
Page
• Is a server side scripting language.
– Capable of generating the HTML pages
• HTML generates the web page with the static text
and images.
• However the need evolved for dynamic web based
application, mostly involving database usage.
Introduction to PHP
PHP FOUNDER
5
Introduction to PHP
Release History
6
Introduction to PHP
Release History
7
Introduction to PHP
8
CLIENT
WEB
SERVER
HTTP Request
(url)
<HTML>
<?php PHP code ?>
</HTML>
Gets Page
<HTML>
<B>Hello</B>
</HTML>
Interprets the PHP code
Server response
Browser creates
the web page
Hello
Introduction to PHP
9
Why PHP?
• ..there are no. of server side scripting available like
ASP, SSJS, JSP…..
• PHP involves
– simplicity in scripting (..generally using the database)
– platform independence.
• PHP is
– primarily designed for web applications
– well optimized for the response times needed for web
applications
• Is an open source.
Introduction to PHP
10
PHP Language features
• PHP language features such as control
structures, operators, variable types, function
declaration, class/object declaration are
almost similar to any compiled or interpreted
language such as C or C++.
Introduction to PHP
11
PHP Data Type
• Three basic data types
– Integer
– Double
– String
• More data types
– Array
– Object
• PHP is an untyped language
– variables type can change on the fly.
Introduction to PHP
12
PHP Block
• PHP code block is embedded within the <?php
and ?> tags.
• When the server encounters the PHP tags it
switches from the HTML to PHP mode.
• There are four different ways to embed the
PHP code
– <?php echo(“Some PHP code”); ?>
– <? echo(“Some PHP code”); ?>
– <SCRIPT Language=‘php’> echo(“Some PHP code”); </SCRIPT>
– <% echo(“Some PHP code”); %>
Introduction to PHP
13
PHP Constants
• ..values that never changes
• Constants are defined in PHP by using the
define() function.
– For e.g.
define(“NCST”, “National Centre for Software Technology”)
• defined() function says whether the constant exists
or not.
Introduction to PHP
14
PHP Variables
• The variables in PHP are declared by
appending the $ sign to the variable name.
– For e.g
$company = “NCST”;
$sum = 10.0;
• variable’s data type is changed by the value
that is assigned to the variable.
• Type casting allows to change the data type
explicitly.
Introduction to PHP
15
PHP Variables (cont.)
• Rich set of functions for working with
variable.
– For e.g
• gettype, settype, isset, unset, is_int, intval etc etc
Introduction to PHP
16
PHP Operators
• All the operators such as arithmetic,
assignment, Comparison, and logical operators
are similar to the operators in C and C++.
• In PHP the string concatenation operator is
denoted by ‘.’.
– For e.g.
• $name = “My name is”.$myname;
Introduction to PHP
17
PHP Statements
• IF statement
if (<condition>) {
//php code goes here
}
else {
//php code goes here
}
• Alternative Syntax
if(<condition>) :
//html code goes here
else :
//html code goes here
endif;
Introduction to PHP
18
PHP Statements (cont.)
• For loop
for($i=0;$i < 10;$++i) {
echo(“the value is :”. $i);
}
– Alternative Syntax
for($i=0;$i < 10;$++i) :
// html code goes here
endfor;
• While loop
• Do-While loop
Introduction to PHP
19
Functions
• Function declaration in PHP
function my_func(<parameters>) {
//do something in the function
}
– for e.g.
function sayHello() {
echo(“<B>hello amrish<B><BR>”);
}
Introduction to PHP
20
Functions (cont.)
• Assigning functions to the variables
– for e.g
• $hello = “my_func”;
• to invoke the function my_func() through the variable
$hello( );
• When an argument is to be passed by
reference, an ampersand (&) is placed before
the parameter name
– for e.g.
my_func(&$my_refvar);
Introduction to PHP
21
Arrays
• ..contains value set
• each element has a value, data stored in the
element.
• And has a key by which the element can be
referred to.
Introduction to PHP
22
Initializing Arrays
• No of ways to initialize the array.
– For e.g.
• $ncststaff[] = “amrish”;
$ncststaff[] = “murali”;
$ncststaff[] = “narayan”;
• $ncststaff[123] = “amrish”;
$ncststaff[122] = “murali”;
$ncststaff[121] = “narayan”;
• $ncststaff = array (“amrish”, “murali”, “narayan”);
– to change the indices of the array use => operator.
Introduction to PHP
23
Accessing the Array Elements
• The elements in the array can be accessed by
using the list and each constructs
– for e.g
while(list($key,$value) = each(countries))
echo(“$value<BR>n”);
– current(<arrayname>) gives the current value
being accessed. key(<arrayname>) gives the index
of the current element that is being accessed.
– prev(<arrayname>) gives the previous element.
– next(<arrayname>) gives the next element.
Introduction to PHP
24
Accessing the Array Elements (cont.)
– Array_walk(<arrayname>,<function_name>)
• function_name is the function that is written for every
member of an array.
• For e.g
$ncststaff = array (“amrish”, “murali”, “narayan”);
array_walk ($ncststaff, printstaff);
// function to print each element of the array
function printstaff($names) {
echo “<B>$names</B><BR>n”;
}
Introduction to PHP
25
Arrays (cont.)
• $ncststaff = array (“dake” => array(“amrish”, “lakshana”, “venkat”),
“spc” => array(“narayan”, “murali”,“prasad”));
–creates a two dimensional array.
• Sorting Functions
– sort() : sorts the elements in the numeric and
alphabetical order.
– rsort() : sorts the elements in the reverse order.
– asort() : sorts the elements in the array without
changing the indices.
– ksort() : sorts the arrays by key.
Introduction to PHP
26
Classes
• Class is a template of an object and includes
the properties and methods that describe an
object and behavior.
• Class in PHP is defined using class statement.
Introduction to PHP
27
Classes (cont.)
• For e.g
<?
class company {
// define the properties
var $companyname;
// define the methods
function company($cname) {
$this->companyname = $cname;
}
function getnames($idcode) {
//return the name of the employee for the required idcode
}
}
?>
Introduction to PHP
28
PHP Richness
• PHP comes with myriad of options i.e.
supports several APIs and interfaces to other
programming tools such as
– Database connectivity.
– LDAP
– XML
– Mail protocols such as IMAP, SMTP
– Image functions
etc….
Introduction to PHP
29
Support for Regular Expressions
• Not pretty things to look at and work with.
– E.g. ^.+@.+..+$
• PHP takes over the headache from the
programmers for explicitly coding for pattern
matching.
• Functions:
– ereg() and eregi()
– ereg_replace() & eregi_replace()
– split()
Introduction to PHP
30
Image Generation & Manipulation
• PHP offers powerful set of functions for
generating and manipulating the images.
– Rendering regular geometric figures, modifying
images
– manipulate text, font and color and even the pixels
in the image.
• ….creating the images on the fly.
Introduction to PHP
31
Image Generation & Manipulation
(cont.)
• PHP uses the GD library for the most of the image
functionality that it offers.
• GD library is used for generating the two-dimensional
graphics.
• PHP API’s provides us with functions to:
– Create, delete, resize and modify images.
– Draw basic geometric figures
– Manipulate text and fonts
– Manipulate colors
– Interlace and manipulate pixels
– Handle PostScript files
Introduction to PHP
32
Mailing functions
• Sending E-Mails
– Mail()
• Used to send simple text messages.
• Depends on the local mail delivery system.
– Using SMTP
• Accepts the e-mail for every recipient and goes through trouble
of delivering the e-mails.
• Receiving E-Mails
– PHP works out well with the IMAP protocol.
– Rich set of support functions
• Imap_open, impa_delete, imap_close, imap_mail_copy,
imap_mail_move etc.
Introduction to PHP
33
PHP-Database Connectivity
• Supports APIs for accessing large number of
databases.
• ODBC is a standard API for accessing a
database that has PHP support.
Introduction to PHP
34
PHP-Database Connectivity
• Some of Oracle 8.x functions.
– OCILogon
– OCILogoff
– OCIParse
– OCIFetch; OCIFetchInto; OCIFetchStatement
– OCIExecute
– OCIFreeStatement
Introduction to PHP
35
LDAP Support in PHP
• PHP provides LDAP API’s that allows the
programmers to create LDAP clients; by
providing transparent access to backend LDAP
directory servers.
– For e.g.
• Web based e-mail client.
• Telephone Directory.
Introduction to PHP
36
XML Support in PHP
• PHP supports a set of functions that can be
used for writing PHP-based XML applications.
• These functions are used for parsing well
formed XML document.
Introduction to PHP
37
THANK YOU

Más contenido relacionado

La actualidad más candente

Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
Arjun Shanka
 

La actualidad más candente (20)

Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php and MySQL
Php and MySQLPhp and MySQL
Php and MySQL
 
Php mysql
Php mysqlPhp mysql
Php mysql
 
Php basics
Php basicsPhp basics
Php basics
 
01 Php Introduction
01 Php Introduction01 Php Introduction
01 Php Introduction
 
Php Tutorials for Beginners
Php Tutorials for BeginnersPhp Tutorials for Beginners
Php Tutorials for Beginners
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
Css ppt
Css pptCss ppt
Css ppt
 
Html basics
Html basicsHtml basics
Html basics
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Html5 and-css3-overview
Html5 and-css3-overviewHtml5 and-css3-overview
Html5 and-css3-overview
 
Php tutorial(w3schools)
Php tutorial(w3schools)Php tutorial(w3schools)
Php tutorial(w3schools)
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
Java script
Java scriptJava script
Java script
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Basic HTML
Basic HTMLBasic HTML
Basic HTML
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 

Destacado

oop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.comoop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.com
tutorialsruby
 
Appendex b
Appendex bAppendex b
Appendex b
swavicky
 
Appendex f
Appendex fAppendex f
Appendex f
swavicky
 
Groundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterGroundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan Schuster
TXGroundwaterSummit
 
5 Accessing Information Resources
5 Accessing Information Resources5 Accessing Information Resources
5 Accessing Information Resources
Patty Ramsey
 
Aquifer Storage and Recovery, Kelley Neumann
Aquifer Storage and Recovery, Kelley NeumannAquifer Storage and Recovery, Kelley Neumann
Aquifer Storage and Recovery, Kelley Neumann
TXGroundwaterSummit
 
Setting up a gmail account
Setting up a gmail accountSetting up a gmail account
Setting up a gmail account
keelyswitzer
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
Chhom Karath
 
CIS 110 Chapter 1 Intro to Computers
CIS 110 Chapter 1 Intro to ComputersCIS 110 Chapter 1 Intro to Computers
CIS 110 Chapter 1 Intro to Computers
Patty Ramsey
 

Destacado (20)

PHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with thisPHP Powerpoint -- Teach PHP with this
PHP Powerpoint -- Teach PHP with this
 
Oop in php_tutorial
Oop in php_tutorialOop in php_tutorial
Oop in php_tutorial
 
oop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.comoop_in_php_tutorial_for_killerphp.com
oop_in_php_tutorial_for_killerphp.com
 
Oop in php tutorial
Oop in php tutorialOop in php tutorial
Oop in php tutorial
 
Php a dynamic web scripting language
Php   a dynamic web scripting languagePhp   a dynamic web scripting language
Php a dynamic web scripting language
 
C# programs
C# programsC# programs
C# programs
 
Appendex b
Appendex bAppendex b
Appendex b
 
Appendex f
Appendex fAppendex f
Appendex f
 
Groundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan SchusterGroundwater Research and Technology, Stefan Schuster
Groundwater Research and Technology, Stefan Schuster
 
Ch07
Ch07Ch07
Ch07
 
PHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet SolutionPHP - Introduction to PHP - Mazenet Solution
PHP - Introduction to PHP - Mazenet Solution
 
5 Accessing Information Resources
5 Accessing Information Resources5 Accessing Information Resources
5 Accessing Information Resources
 
Aquifer Storage and Recovery, Kelley Neumann
Aquifer Storage and Recovery, Kelley NeumannAquifer Storage and Recovery, Kelley Neumann
Aquifer Storage and Recovery, Kelley Neumann
 
Setting up a gmail account
Setting up a gmail accountSetting up a gmail account
Setting up a gmail account
 
Application of dual output LiDAR scanning system for power transmission line ...
Application of dual output LiDAR scanning system for power transmission line ...Application of dual output LiDAR scanning system for power transmission line ...
Application of dual output LiDAR scanning system for power transmission line ...
 
Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)Ch4(saving state with cookies and query strings)
Ch4(saving state with cookies and query strings)
 
Offshore pipelines
Offshore pipelinesOffshore pipelines
Offshore pipelines
 
CIS 110 Chapter 1 Intro to Computers
CIS 110 Chapter 1 Intro to ComputersCIS 110 Chapter 1 Intro to Computers
CIS 110 Chapter 1 Intro to Computers
 
Emoji International Name Finder
Emoji International Name FinderEmoji International Name Finder
Emoji International Name Finder
 
Unix Master
Unix MasterUnix Master
Unix Master
 

Similar a Introduction to php

Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Muhamad Al Imran
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Muhamad Al Imran
 

Similar a Introduction to php (20)

Php
PhpPhp
Php
 
Initializing arrays
Initializing arraysInitializing arrays
Initializing arrays
 
php 1
php 1php 1
php 1
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
Php i basic chapter 3 (mardhiah kamaludin's conflicted copy 2013-04-23)
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
Php
PhpPhp
Php
 
PHP MySQL Workshop - facehook
PHP MySQL Workshop - facehookPHP MySQL Workshop - facehook
PHP MySQL Workshop - facehook
 
Hsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdfHsc IT 5. Server-Side Scripting (PHP).pdf
Hsc IT 5. Server-Side Scripting (PHP).pdf
 
phpwebdev.ppt
phpwebdev.pptphpwebdev.ppt
phpwebdev.ppt
 
Php training100%placement-in-mumbai
Php training100%placement-in-mumbaiPhp training100%placement-in-mumbai
Php training100%placement-in-mumbai
 
Website designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopmentWebsite designing company_in_delhi_phpwebdevelopment
Website designing company_in_delhi_phpwebdevelopment
 
Php Basics
Php BasicsPhp Basics
Php Basics
 
Materi Dasar PHP
Materi Dasar PHPMateri Dasar PHP
Materi Dasar PHP
 
PHP
PHPPHP
PHP
 
Php tutorialw3schools
Php tutorialw3schoolsPhp tutorialw3schools
Php tutorialw3schools
 
Chap 4 PHP.pdf
Chap 4 PHP.pdfChap 4 PHP.pdf
Chap 4 PHP.pdf
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 

Más de Anjan Banda (9)

Seo tutorial
Seo tutorialSeo tutorial
Seo tutorial
 
Css3
Css3Css3
Css3
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 
Website Networking
Website Networking Website Networking
Website Networking
 
crisis-in-textile-industry
crisis-in-textile-industrycrisis-in-textile-industry
crisis-in-textile-industry
 
Genetic engineering
Genetic engineeringGenetic engineering
Genetic engineering
 
Android os
Android osAndroid os
Android os
 
Body area-networks
Body area-networksBody area-networks
Body area-networks
 
Woods Of Pakistan
Woods Of PakistanWoods Of Pakistan
Woods Of Pakistan
 

Último

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Último (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 

Introduction to php

  • 1. Introduction to PHP 1 Introduction to PHP AIMS BBSYDP TRAINING JUNAID NAZIR junaid@comelearnshare.com
  • 2. Introduction to PHP Introduction to PHP • PHP is a server-side scripting language designed for web development but also used as a general- purpose programming language. As of January 2013, PHP was installed on more than 240 million websites (39% of those sampled) and 2.1 million web servers.[Originally created by Ramses Lerdorf in 1994,the reference implementation of PHP is now produced by The PHP Group. While PHP originally stood for Personal Home Page, it now stands for PHP: Hypertext Preprocessor, a recursive backronym. • 2
  • 3. Introduction to PHP Introduction to PHP • PHP code can be simply mixed with HTML code, or it can be used in combination with various templating engines and web frameworks. PHP code is usually processed by a PHP interpreter, which is usually implemented as a web server's native module or aCommon Gateway Interface (CGI) executable. After the PHP code is interpreted and executed, the web server sends resulting output to its client, usually in form of a part of the generated web page – for example, PHP code can generate a web page's HTML code, an image, or some other data. PHP has also evolved to include a command-line interface (CLI) capability and can be used in standalonegraphical applications. • 3
  • 4. Introduction to PHP 4 Introduction to PHP • PHP Hypertext Preprocessor. – Other Names : Personal Home Page, Professional Home Page • Is a server side scripting language. – Capable of generating the HTML pages • HTML generates the web page with the static text and images. • However the need evolved for dynamic web based application, mostly involving database usage.
  • 8. Introduction to PHP 8 CLIENT WEB SERVER HTTP Request (url) <HTML> <?php PHP code ?> </HTML> Gets Page <HTML> <B>Hello</B> </HTML> Interprets the PHP code Server response Browser creates the web page Hello
  • 9. Introduction to PHP 9 Why PHP? • ..there are no. of server side scripting available like ASP, SSJS, JSP….. • PHP involves – simplicity in scripting (..generally using the database) – platform independence. • PHP is – primarily designed for web applications – well optimized for the response times needed for web applications • Is an open source.
  • 10. Introduction to PHP 10 PHP Language features • PHP language features such as control structures, operators, variable types, function declaration, class/object declaration are almost similar to any compiled or interpreted language such as C or C++.
  • 11. Introduction to PHP 11 PHP Data Type • Three basic data types – Integer – Double – String • More data types – Array – Object • PHP is an untyped language – variables type can change on the fly.
  • 12. Introduction to PHP 12 PHP Block • PHP code block is embedded within the <?php and ?> tags. • When the server encounters the PHP tags it switches from the HTML to PHP mode. • There are four different ways to embed the PHP code – <?php echo(“Some PHP code”); ?> – <? echo(“Some PHP code”); ?> – <SCRIPT Language=‘php’> echo(“Some PHP code”); </SCRIPT> – <% echo(“Some PHP code”); %>
  • 13. Introduction to PHP 13 PHP Constants • ..values that never changes • Constants are defined in PHP by using the define() function. – For e.g. define(“NCST”, “National Centre for Software Technology”) • defined() function says whether the constant exists or not.
  • 14. Introduction to PHP 14 PHP Variables • The variables in PHP are declared by appending the $ sign to the variable name. – For e.g $company = “NCST”; $sum = 10.0; • variable’s data type is changed by the value that is assigned to the variable. • Type casting allows to change the data type explicitly.
  • 15. Introduction to PHP 15 PHP Variables (cont.) • Rich set of functions for working with variable. – For e.g • gettype, settype, isset, unset, is_int, intval etc etc
  • 16. Introduction to PHP 16 PHP Operators • All the operators such as arithmetic, assignment, Comparison, and logical operators are similar to the operators in C and C++. • In PHP the string concatenation operator is denoted by ‘.’. – For e.g. • $name = “My name is”.$myname;
  • 17. Introduction to PHP 17 PHP Statements • IF statement if (<condition>) { //php code goes here } else { //php code goes here } • Alternative Syntax if(<condition>) : //html code goes here else : //html code goes here endif;
  • 18. Introduction to PHP 18 PHP Statements (cont.) • For loop for($i=0;$i < 10;$++i) { echo(“the value is :”. $i); } – Alternative Syntax for($i=0;$i < 10;$++i) : // html code goes here endfor; • While loop • Do-While loop
  • 19. Introduction to PHP 19 Functions • Function declaration in PHP function my_func(<parameters>) { //do something in the function } – for e.g. function sayHello() { echo(“<B>hello amrish<B><BR>”); }
  • 20. Introduction to PHP 20 Functions (cont.) • Assigning functions to the variables – for e.g • $hello = “my_func”; • to invoke the function my_func() through the variable $hello( ); • When an argument is to be passed by reference, an ampersand (&) is placed before the parameter name – for e.g. my_func(&$my_refvar);
  • 21. Introduction to PHP 21 Arrays • ..contains value set • each element has a value, data stored in the element. • And has a key by which the element can be referred to.
  • 22. Introduction to PHP 22 Initializing Arrays • No of ways to initialize the array. – For e.g. • $ncststaff[] = “amrish”; $ncststaff[] = “murali”; $ncststaff[] = “narayan”; • $ncststaff[123] = “amrish”; $ncststaff[122] = “murali”; $ncststaff[121] = “narayan”; • $ncststaff = array (“amrish”, “murali”, “narayan”); – to change the indices of the array use => operator.
  • 23. Introduction to PHP 23 Accessing the Array Elements • The elements in the array can be accessed by using the list and each constructs – for e.g while(list($key,$value) = each(countries)) echo(“$value<BR>n”); – current(<arrayname>) gives the current value being accessed. key(<arrayname>) gives the index of the current element that is being accessed. – prev(<arrayname>) gives the previous element. – next(<arrayname>) gives the next element.
  • 24. Introduction to PHP 24 Accessing the Array Elements (cont.) – Array_walk(<arrayname>,<function_name>) • function_name is the function that is written for every member of an array. • For e.g $ncststaff = array (“amrish”, “murali”, “narayan”); array_walk ($ncststaff, printstaff); // function to print each element of the array function printstaff($names) { echo “<B>$names</B><BR>n”; }
  • 25. Introduction to PHP 25 Arrays (cont.) • $ncststaff = array (“dake” => array(“amrish”, “lakshana”, “venkat”), “spc” => array(“narayan”, “murali”,“prasad”)); –creates a two dimensional array. • Sorting Functions – sort() : sorts the elements in the numeric and alphabetical order. – rsort() : sorts the elements in the reverse order. – asort() : sorts the elements in the array without changing the indices. – ksort() : sorts the arrays by key.
  • 26. Introduction to PHP 26 Classes • Class is a template of an object and includes the properties and methods that describe an object and behavior. • Class in PHP is defined using class statement.
  • 27. Introduction to PHP 27 Classes (cont.) • For e.g <? class company { // define the properties var $companyname; // define the methods function company($cname) { $this->companyname = $cname; } function getnames($idcode) { //return the name of the employee for the required idcode } } ?>
  • 28. Introduction to PHP 28 PHP Richness • PHP comes with myriad of options i.e. supports several APIs and interfaces to other programming tools such as – Database connectivity. – LDAP – XML – Mail protocols such as IMAP, SMTP – Image functions etc….
  • 29. Introduction to PHP 29 Support for Regular Expressions • Not pretty things to look at and work with. – E.g. ^.+@.+..+$ • PHP takes over the headache from the programmers for explicitly coding for pattern matching. • Functions: – ereg() and eregi() – ereg_replace() & eregi_replace() – split()
  • 30. Introduction to PHP 30 Image Generation & Manipulation • PHP offers powerful set of functions for generating and manipulating the images. – Rendering regular geometric figures, modifying images – manipulate text, font and color and even the pixels in the image. • ….creating the images on the fly.
  • 31. Introduction to PHP 31 Image Generation & Manipulation (cont.) • PHP uses the GD library for the most of the image functionality that it offers. • GD library is used for generating the two-dimensional graphics. • PHP API’s provides us with functions to: – Create, delete, resize and modify images. – Draw basic geometric figures – Manipulate text and fonts – Manipulate colors – Interlace and manipulate pixels – Handle PostScript files
  • 32. Introduction to PHP 32 Mailing functions • Sending E-Mails – Mail() • Used to send simple text messages. • Depends on the local mail delivery system. – Using SMTP • Accepts the e-mail for every recipient and goes through trouble of delivering the e-mails. • Receiving E-Mails – PHP works out well with the IMAP protocol. – Rich set of support functions • Imap_open, impa_delete, imap_close, imap_mail_copy, imap_mail_move etc.
  • 33. Introduction to PHP 33 PHP-Database Connectivity • Supports APIs for accessing large number of databases. • ODBC is a standard API for accessing a database that has PHP support.
  • 34. Introduction to PHP 34 PHP-Database Connectivity • Some of Oracle 8.x functions. – OCILogon – OCILogoff – OCIParse – OCIFetch; OCIFetchInto; OCIFetchStatement – OCIExecute – OCIFreeStatement
  • 35. Introduction to PHP 35 LDAP Support in PHP • PHP provides LDAP API’s that allows the programmers to create LDAP clients; by providing transparent access to backend LDAP directory servers. – For e.g. • Web based e-mail client. • Telephone Directory.
  • 36. Introduction to PHP 36 XML Support in PHP • PHP supports a set of functions that can be used for writing PHP-based XML applications. • These functions are used for parsing well formed XML document.