introduction to php software freedom day1 introduction to php ms. sadaf abbasi [email protected]
TRANSCRIPT
![Page 2: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/2.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 2
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.
![Page 3: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/3.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 3
CLIENT
WEB SERVER
HTTP Request(url)
<HTML><?php PHP code ?></HTML>
Gets Page
<HTML><B>Hello</B></HTML>
Interprets the PHP codeServer response
Browser createsthe web page
Hello
![Page 4: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/4.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 4
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.
![Page 5: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/5.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 5
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++.
![Page 6: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/6.jpg)
Introduction to PHP
Features of PHP•It is Free and Open source.•Easy to learn but hard to master.•Connects with 20+ databases.•Version 5+ supports OOP.•Multi-platform compatible.
SOFTWARE FREEDOM DAY 6
![Page 7: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/7.jpg)
Introduction to PHP
The WAMP/LAMP Stack
SOFTWARE FREEDOM DAY 7
Apache is the web server.MYSQL is the database server.PHP is the backend coding language.
![Page 8: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/8.jpg)
Introduction to PHP
IDEs for PHP development
• IDE – Integrated Development Environment– Adobe Dreameweaver
– Notepad++
– Dev-PHP
– Zend Development Studio
– PHP Eclipse
SOFTWARE FREEDOM DAY 8
![Page 9: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/9.jpg)
Introduction to PHP
PHP Trend
SOFTWARE FREEDOM DAY 9
![Page 10: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/10.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 10
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.
![Page 11: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/11.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 11
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”); %>
![Page 12: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/12.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 12
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.
![Page 13: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/13.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 13
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.
![Page 14: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/14.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 14
PHP Variables (cont.)• Rich set of functions for working with
variable.– For e.g
• gettype, settype, isset, unset, is_int, intval etc etc
![Page 15: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/15.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 15
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;
![Page 16: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/16.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 16
PHP Statements• IF statement
if (<condition>) {//php code goes here}
else {//php code goes here}
• Alternative Syntaxif(<condition>) :
//html code goes here
else ://html code goes here
endif;
![Page 17: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/17.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 17
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
![Page 18: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/18.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 18
Functions
• Function declaration in PHPfunction my_func(<parameters>) {
//do something in the function
}
– for e.g.function sayHello() {
echo(“<B>hello amrish<B><BR>”);
}
![Page 19: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/19.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 19
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);
![Page 20: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/20.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 20
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.
![Page 21: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/21.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 21
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.
![Page 22: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/22.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 22
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.
![Page 23: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/23.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 23
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”;
}
![Page 24: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/24.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 24
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.
![Page 25: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/25.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 25
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.
![Page 26: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/26.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 26
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
}
}
?>
![Page 27: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/27.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 27
PHP Richness
• PHP comes with myriad of options i.e. supports several APIs and interfaces to other programming tools such as– Database connectivity.
– XML
– Mail protocols such as IMAP, SMTP
– Image functions
etc….
![Page 28: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/28.jpg)
Introduction to PHP
A. SOFTWARE FREEDOM DAY 28
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.
![Page 29: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/29.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 29
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
![Page 30: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/30.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 30
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.
![Page 31: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/31.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 31
PHP-Database Connectivity
• Supports APIs for accessing large number of databases.
• ODBC is a standard API for accessing a database that has PHP support.
![Page 32: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/32.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 32
PHP-Database Operations
• Some of operations.– Insert Data
– Delete Data
– Search Data
– Update Data
![Page 33: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/33.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 33
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.
![Page 34: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/34.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 34
References
• Professional PHP programming– By Jesus Castagnetto, Chris Schollo et al
• www.phpbuilder.com
• www.php.net
![Page 35: Introduction to PHP SOFTWARE FREEDOM DAY1 Introduction to PHP MS. SADAF ABBASI abasy@qu.edu.sa](https://reader035.vdocuments.net/reader035/viewer/2022062620/551bbbd1550346be588b471a/html5/thumbnails/35.jpg)
Introduction to PHP
SOFTWARE FREEDOM DAY 35
THANK YOU