Professional Documents
Culture Documents
USING PHP
Rameela Ravindran K
INTRODUCTION TO PHP
Web development language
stands for :- Hypertext Preprocessor
server-side scripting language- can be embedded in
HTMLons to love
Reasons to love Php
Cost
Server
Popularity
Not proprietary (not tied to any one server
operating)
anything
the client
client-side technologies cannot do anything that requires
connecting to a back end server. JavaScript cannot
assemble a customized drop-down list on the fly from
user preferences stored in a database
upgrades
InterNIC registration, IP addressing, DNS
Mail servers (POP/IMAP and SMTP)
Bandwidth
Power supply
Backups
Security
INSTALLING PHP
A server or workstation with enough RAM for OS
Unix, Mac OS X, or Windows operating system
Working, dedicated Internet connection
Install PHP on Windows:
Working
Extract the binary archive using unzip utility; C:\PHP -common location.
Copy .dll files from PHP directory to systems directory (usually
C:\Winnt\System32). php5ts.dll , Web server moduleC:\PHP\Sapi\
php5isapi.dll., dlls subfolder are the necessary to be copied to the system
Copy either php.ini-dist or php.ini-recommended to Windows
directory (C:\Winnt or C:\Winnt40), and rename it php.ini. Open this file in
a text editor. Edit this file to get configuration directives. Set error reporting
to E_ALL on their development machines at this point. For now, the most
important thing is the doc_root directive under the Paths and Directories
sectionmake sure this matches your IIS Inetpub folder
Stop and restart the WWW service. Go to the Start menu Settings
Control Panel Services. Scroll down the list to IIS Admin Service.
Select it and click Stop. After it stops, select World Wide Web Publishing
Service and click Start. Stopping and restarting the service from within
Internet Service Manager.
5. Open a text editor Type: <?php phpinfo(); ?>. Save this file in your
Web servers document root as info.php. Start any Web browser and browse
the fileyou must always use an HTTP request (
http://www.testdomain.com/info.php or http://localhost/info.php or
http://127.0.0.1/info.php) rather than a filename
(C:\inetpub\wwwroot\info.php) for the file to be parsed correctly. You
should see a long table of information about your new PHP5 installation.
ASP-style
$greetings
=Welcome to PHP;
COMMENTS
VARIABLES
denoted with a leading dollar sign ($).
value of a variable is the value of its most recent
assignment.
need not to be declared before assignment.
no intrinsic type other than the type of their
current value.
have default values.
Variable = value
Variable Scope
Global
Local
Defined Constants
Define(variablename,
Pre-defined variables
$_GET
$_POST
$_COOKIE
$_FILES
$_ENV
$_SESSION
value);
DATA TYPES
PHP has a total of eight types: .
Integers are whole numbers, without a decimal point, like
495. range -231-1 to 231-1
Doubles are floating-point numbers, like 3.14159 or 49.0.
Booleans have only two possible values: TRUE and FALSE.
NULL is a special type that only has one value: NULL.
Strings are sequences of characters, like PHP 4.0 supports
string operations.
Arrays are named and indexed collections of other values.
Objects are instances of programmer-defined classes, which
can package up both other kinds of values and functions that
are specific to the class.
Resources are special variables that hold references to
resources external to PHP (such as database connections).
Output:
The
Or equivalently:
Break
Continue
Alternate control syntaxes
FUNCTION
{
}
Function function_name($argument_1,$argument_1)
Call by value
Call by reference
Default argument
Return by value
Function &function_name($argument_1,$argument_1)
{
Return $variable;
}
$variable= &function_name;
OPERATORS
Arithmetic operators
Increment decrement operators
Comparison operators
Logical operators
String operators
Bitwise operators
Assignment operators
GET ARGUMENTS
The GET method passes arguments from one
page to the next as part of the Uniform Resource
Indicator query string.
When used for form handling, GET appends the
indicated variable name(s) and value(s) to the
URL designated in the ACTION attribute with a
question mark separator and submits the whole
thing to the processing agent- a Web server
<HTML>
<HEAD>
<TITLE>A GET method example, part 1</TITLE>
</HEAD>
<BODY>
<FORM ACTION=http://localhost/baseball.php METHOD=GET>
<P>Root, root, root for the:<BR>
<SELECT NAME=Team SIZE=2>
<OPTION VALUE=Cubbies>Chicago Cubs (National
League)</OPTION>
<OPTION VALUE=Pale Hose>Chicago White Sox (American
League)</OPTION>
</SELECT>
<P><INPUT TYPE=submit NAME=Submit VALUE=Select>
</P>
</FORM>
</BODY>
</HTML>
When the user makes a selection and clicks the Submit button,
the browser agglutinates these elements in this order, with no
spaces between the elements:
The URL in quotes after the word ACTION (
http://localhost/baseball.php)
It then forwards this URL into its own address space as a new
request. The PHP script to which the preceding form is submitted
(baseball.php) will grab the GET variables from the end of the
request string, stuff them into the $_GET superglobal array.
The following code sample shows the PHP form handler for the
preceding HTML form:
<HTML>
<HEAD>
<TITLE>A GET method example, part 2</TITLE>
<STYLE>
</HEAD>
<BODY>
<P>Go,
<?php echo $_GET[Team]; ?>
!</P>
</BODY>
</HTML>
HTTP COOKIES
HTTP SESSION
ARRAY
Create array
By
By
using array()
$my_array=array();
$my_array= array(apple, orange, pear);
$my_array[0]= apple;
$my_array[1]=pear;
$my_array= array(1,1,52,73);
By
RETRIEVING VALUE
Index
Echo
List()
$my_array[1];
$my_array=
MULTIDIMENSIONAL ARRAY
unset()
Iteration
Hidden
Foreach($a as $v)
While(list($key,$val)=each($array)
Array functions
Is_array($myarray)
Count($myarray)
Sizeof()
// nonempty elements
In_array($myarray,
a)
Isset($myarray[$key] // key is valid or not
ARRAY OPERATIONS
Union (+)
Equality(==) // same key value pair
Identity (===)// same key value pair in the same
order and of same type
Inequality (!= <>)
Non identity (!==)
ARRAY FUNCTION
Is_array()
Array_fill($startindex,$num,$value)
Array_key_exists($key, $array)
Array_sum($myarray)
Array_count_values // array using the values of
the input as key and their frequency as values
Array_unique()
Sort(&$my_array[,$sort_flag=______)
Sort_regular
Sort_numeric
sort_string
Asort(&$my_array[,$sort_flag= -------------)
Rsort((&$my_array[,$sort_flag= -------------)
arsort (&$my_array[,$sort_flag= -------------)
ksort (&$my_array[,$sort_flag= -------------) //sort
by key
krsort (&$my_array[,$sort_flag= -------------)
natsort (&$my_array[,$sort_flag= -------------)
natcasesort (&$my_array[,$sort_flag= -------------)
In_array($value,$array)
Each($array) // return each key value pair
List()
Current($array) // return current element
Next()
Pre()
End() // sets the pointer to the last element
Reset()
count()
STRINGS IN PHP
Sequence of characters
Accessed using index
concatenation using .
Heredoc syntax <<<
$string_value= <<<identifier
Text
Identifier;
STRING FUNCTIONS
Strlen($string)
Strops()
strpos($mystring,$findme[,offset=0])
Mystring
string to be searched in
Findme item to be searched
Offset which character to start searching
$pos= strpos($mystring,$findme)
Strrpos()
Postion
Stripos()
Strripos()
str
DATABASE
Collection of data with regular and predictable
structure
Examples :
postgreSQL
MySQL
SQL
Server
Oracle
MYSQL
Freeware
Stable no crashing
Lightweight require no