Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Introduction to PHP - Lecture - PHP - Prof G H Haldar, Lecture notes of Programming Languages

In this document description about PHP, What is PHP? , Why PHP? , What do You Need? , PHP Syntax .

Typology: Lecture notes

2010/2011
On special offer
60 Points
Discount

Limited-time offer


Uploaded on 09/06/2011

singh-chavan
singh-chavan 🇮🇳

4

(1)

1 document

1 / 89

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PHP
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
Discount

On special offer

Partial preview of the text

Download Introduction to PHP - Lecture - PHP - Prof G H Haldar and more Lecture notes Programming Languages in PDF only on Docsity!

PHP

What is PHP?

PHP stands for P HP: H ypertext P reprocessor

 PHP is a server-side scripting language, like ASP

 PHP scripts are executed on the server

 PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid,

PostgreSQL, Generic ODBC, etc.)

 PHP is an open source software (OSS)

 PHP is free to download and use

What do You Need?

 Download PHP

 Download PHP for free here: http://www.php.net/downloads.php

 Download MySQL Database

 Download MySQL for free here:

http://www.mysql.com/downloads/index.html

 Download Apache Server

 Download Apache for free here: http://httpd.apache.org/download.cgi

PHP Syntax

 Basic PHP Syntax

 A PHP file normally contains HTML tags, just like an HTML file, and

some PHP scripting code.

 Comments in PHP

 // ----to make a single-line comment or

 /* */ --- multiple lines

PHP Variables

 All variables in PHP start with a $ sign symbol.

$var_name = value;

 variable does not need to be declared before being set

 declared automatically when you use it

 Variable Naming Rules

 A variable name must start with a letter or an underscore "_"

 A variable name can only contain alpha-numeric characters and

underscores (a-Z, 0-9, and _ )

 A variable name should not contain spaces (use underscore)

Strings in PHP

 used for values that contains character strings
 The Concatenation Operator (.)
 concatenate two variables together
 strlen() function
 used to find the length of a string
 strpos() function
 used to search for a string or character within a string
 echo strpos("Hello world!","world");

Strings in PHP  (^) http://www.w3schools.com/php/php_ref_string.asp

PHP Operators

PHP constant

 like a variable,
 is a temporary placeholder in memory that holds a value.
 Unlike variables, the value of a constant never changes.
 PHP constants unlike variables do not begin with the "$" sign.
 When a constant is declared, the define() function is used and requires the name of the
constant and the value you want to give the constant
 Constants can be assigned the following types of data:
Integers - whole numbers or numbers without decimals.
Floating-point numbers (also known as floats or doubles) -
Strings - text or numeric information.

PHP constant

 define("STRING_CONSTANT", "This is my string.");

define("NUMERIC_CONSTANT", 5);

Flow Control Statements

 Conditional Statements

1. "if ... elseif ... else" statements.
if ( condition )
code to be executed if condition is true;
else code to be executed if condition is false;
2. "switch ... case ... default" statements.
 If you want to select one of many blocks of code to be executed, use the Switch
statement.
 The switch statement is used to avoid long blocks of if..elseif..else code.
 After a code is executed, break is used to stop the code from running into the
next case

Flow Control Statements

 Looping

 while - loops through a block of code if and as long as a specified condition
is true
 do...while - loops through a block of code once, and then repeats the loop as
long as a special condition is true. will execute a block of code at least once
 for - loops through a block of code a specified number of times
 foreach - loops through a block of code for each element in an array

foreach ( array as value ) { code to be executed; }

PHP Arrays

2. Associative Arrays

 each ID key is associated with a value.
 we can use the values as keys and assign values to them
 E.g. 1
 $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34);
 E.g. 2
$ages['Peter'] = "32";
$ages['Quagmire'] = "30";
$ages['Joe'] = "34";

PHP Arrays

3. Multidimensional Arrays

 (^) each element in the main array can also be an array.  (^) And each element in the sub-array can be an array, and so on.  (^) E.g. in practical