LEARN PHP

1. INTRODUCTION
PHP is a server-side scripting language.
What You Should Already Know Before you continue you should have a basic understanding of the following: HTML/XHTML JavaScript If you want to study these subjects first, find the tutorials on our Home page.

What is PHP?
     
PHP stands for PHP: Hypertext Preprocessor 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 PHP is free to download and use

What is a PHP File?
  
PHP files can contain text, HTML tags and scripts PHP files are returned to the browser as plain HTML PHP files have a file extension of ".php", ".php3", or ".phtml"

What is MySQL?
    
MySQL MySQL MySQL MySQL MySQL is a database server is ideal for both small and large applications supports standard SQL compiles on a number of platforms is free to download and use

PHP + MySQL

PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)

Why PHP?
   
PHP PHP PHP PHP runs on different platforms (Windows, Linux, Unix, etc.) is compatible with almost all servers used today (Apache, IIS, etc.) is FREE to download from the official PHP resource: www.php.net is easy to learn and runs efficiently on the server side

Where to Start?
To get access to a web server with PHP support, you can:

 

Install Apache (or IIS) on your own server, install PHP, and MySQL Or find a web hosting plan with PHP and MySQL support

What do you Need?
If your server supports PHP you don't need to do anything. Just create some .php files in your web directory, and the server will parse them for you. Because it is free, most web hosts offer PHP support. However, if your server does not support PHP, you must install PHP. Here is a link to a good tutorial from PHP.net on how to install PHP5:http://www.php.net/manual/en/install.php

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/

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

PHP code is executed on the server, and the plain HTML result is sent to the browser.

2. Basic PHP Syntax
A PHP scripting block always starts with <?php and ends with ?>. A PHP scripting block can be placed anywhere in the document. On servers with shorthand support enabled you can start a scripting block with <? and end with ?>. For maximum compatibility, we recommend that you use the standard form (<?php) rather than the shorthand form.

<?php ?>
A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code. Below, we have an example of a simple PHP script which sends the text "Hello World" to the browser:

<html> <body> <?php echo "Hello World"; ?> </body> </html>
Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another. There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text "Hello World".

Note: The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.

Comments in PHP
In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.

<html> <body> <?php //This is a comment /* This is

a comment block */ ?> </body> </html> A variable is used to store information. .

Variables in PHP Variables are used for storing values. The correct way of declaring a variable in PHP: $var_name = value. depending on its value. All variables in PHP start with a $ sign symbol. 0-9. New PHP programmers often forget the $ sign at the beginning of the variable. $x=16.3. a variable does not need to be declared before adding a value to it. If a variable name is more than one word. like text strings. and a variable containing a number: <?php $txt="Hello World!". In the example above. and _ ) A variable name should not contain spaces. PHP automatically converts the variable to the correct data type. you have to declare (define) the type and name of the variable before using it. Let's try creating a variable containing a string. In a strongly typed programming language. A-Z. the variable is declared automatically when you use it. In PHP. Naming Rules for Variables    A variable name must start with a letter or an underscore "_" A variable name can only contain alpha-numeric characters and underscores (a-z. In that case it will not work. numbers or arrays. ?> PHP is a Loosely Typed Language In PHP. When a variable is declared. . you see that you do not have to tell PHP which data type the variable is. it can be used over and over again in your script. it should be separated with an underscore ($my_string). or with capitalization ($myString) A string variable is used to store and manipulate text.

echo $txt1 . A string can be used directly in a function or it can be stored in a variable. $txt2. ?> The output of the code above will be: Hello World! What a nice day! If we look at the code above you see that we used the concatenation operator two times. the PHP script assigns the text "Hello World" to a string variable called $txt: <?php $txt="Hello World". lets try to use some different functions and operators to manipulate the string.String Variables in PHP String variables are used for values that contains characters. The strlen() function . $txt2="What a nice day!". After we create a string we can manipulate it. to separate the two strings. Below. The Concatenation Operator There is only one string operator in PHP. To concatenate two string variables together. This is because we had to insert a third string (a space character). ?> The output of the code above will be: Hello World Now. " " .) is used to put two string values together. use the concatenation operator: <?php $txt1="Hello World!". echo $txt. In this chapter we are going to look at the most common functions and operators used to manipulate strings in PHP. The concatenation operator (.

it will return FALSE.e. The reason that it is 6 (and not 7). when it is important to know when the string ends. ?> The output of the code above will be: 12 The length of a string is often used in loops or other functions. and not 1."world"). If no match is found. If a match is found.The strlen() function is used to return the length of a string. ?> The output of the code above will be: 6 The position of the string "world" in our string is position 6. in a loop. is that the first position in the string is 0. . (i. we would want to stop the loop after the last character in the string) The strpos () function The strpos () function is used to search for character within a string. Let's find the length of a string: <?php echo strlen("Hello world!"). this function will return the position of the first match. Let's see if we can find the string "world" in our string: <?php echo strpos("Hello world!".

The reference contains a brief description.4. and examples of use. There is no installation needed to use these functions. for each function! PHP String Introduction The string functions allow you to manipulate strings. Complete PHP String Reference For a complete reference of all string functions. Installation The string functions are part of the PHP core. go to our complete PHP String Reference. PHP String Functions PHP: indicates the earliest version of PHP that supports the function. Function addcslashes() addslashes() bin2hex() chop() chr() chunk_split() convert_cyr_string() convert_uudecode() convert_uuencode() count_chars() crc32() crypt() echo() explode() fprintf() Description PHP Returns a string with backslashes in front of the specified 4 characters Returns a string with backslashes in front of predefined characters Converts a string of ASCII characters to hexadecimal values Alias of rtrim() Returns a character from a specified ASCII value Splits a string into a series of smaller parts Converts a string from one Cyrillic character-set to another Decodes a uuencoded string Encodes a string using the uuencode algorithm Returns how many times an ASCII character occurs within a string and returns the information Calculates a 32-bit CRC for a string One-way string encryption (hashing) Outputs strings Breaks a string into an array Writes a formatted string to a specified output stream 3 3 3 3 3 3 5 5 4 4 3 3 3 5 .

get_html_translation_table() hebrev() hebrevc() html_entity_decode() htmlentities() htmlspecialchars_decode() htmlspecialchars() implode() join() levenshtein() localeconv() ltrim() md5() md5_file() metaphone() money_format() nl_langinfo() nl2br() number_format() ord() parse_str() print() printf() quoted_printable_decode() quotemeta() rtrim() setlocale() sha1() sha1_file() similar_text() soundex() sprintf() sscanf() str_ireplace() str_pad() str_repeat() str_replace() Returns the translation table used by htmlspecialchars() and htmlentities() Converts Hebrew text to visual text Converts Hebrew text to visual text and new lines (\n) into <br /> Converts HTML entities to characters Converts characters to HTML entities Converts some predefined HTML entities to characters Converts some predefined characters to HTML entities Returns a string from the elements of an array Alias of implode() Returns the Levenshtein distance between two strings Returns locale numeric and monetary formatting information Strips whitespace from the left side of a string Calculates the MD5 hash of a string Calculates the MD5 hash of a file Calculates the metaphone key of a string Returns a string formatted as a currency string Returns specific local information Inserts HTML line breaks in front of each newline in a string Formats a number with grouped thousands Returns the ASCII value of the first character of a string Parses a query string into variables Outputs a string Outputs a formatted string Decodes a quoted-printable string Quotes meta characters Strips whitespace from the right side of a string Sets locale information Calculates the SHA-1 hash of a string Calculates the SHA-1 hash of a file Calculates the similarity between two strings Calculates the soundex key of a string Writes a formatted string to a variable Parses input from a string according to a format Replaces some characters in a string (case-insensitive) Pads a string to a new length Repeats a string a specified number of times Replaces some characters in a string (case-sensitive) 4 3 3 4 3 5 3 3 3 3 4 3 3 4 4 4 4 3 3 3 3 3 3 3 3 3 3 4 4 3 3 3 4 5 4 4 3 .

str_rot13() str_shuffle() str_split() str_word_count() strcasecmp() strchr() strcmp() strcoll() strcspn() strip_tags() stripcslashes() stripslashes() stripos() stristr() strlen() strnatcasecmp() strnatcmp() strncasecmp() strncmp() strpbrk() strpos() strrchr() strrev() strripos() strrpos() strspn() strstr() strtok() strtolower() strtoupper() strtr() Performs the ROT13 encoding on a string Randomly shuffles all characters in a string Splits a string into an array Count the number of words in a string Compares two strings (case-insensitive) 4 4 5 4 3 Finds the first occurrence of a string inside another string 3 (alias of strstr()) Compares two strings (case-sensitive) Locale based string comparison 3 4 Returns the number of characters found in a string before 3 any part of some specified characters are found Strips HTML and PHP tags from a string Unquotes a string quoted with addcslashes() Unquotes a string quoted with addslashes() Returns the position of the first occurrence of a string inside another string (case-insensitive) 3 4 3 5 Finds the first occurrence of a string inside another string 3 (case-insensitive) Returns the length of a string Compares two strings using a "natural order" algorithm (case-insensitive) Compares two strings using a "natural order" algorithm (case-sensitive) String comparison of the first n characters (caseinsensitive) String comparison of the first n characters (casesensitive) Searches a string for any of a set of characters Returns the position of the first occurrence of a string inside another string (case-sensitive) Finds the last occurrence of a string inside another string Reverses a string 3 4 4 4 4 5 3 3 3 Finds the position of the last occurrence of a string inside 5 another string (case-insensitive) Finds the position of the last occurrence of a string inside 3 another string (case-sensitive) Returns the number of characters found in a string that contains only characters from a specified charlist 3 Finds the first occurrence of a string inside another string 3 (case-sensitive) Splits a string into smaller strings Converts a string to lowercase letters Converts a string to uppercase letters Translates certain characters in a string 3 3 3 3 .

0 otherwise Set to 1 if the extended DES-based encryption with a 9 character salt is supported. the length is 2 Set to 1 if the standard DES-based encryption with a 2 character salt is supported.substr() substr_compare() substr_count() substr_replace() trim() ucfirst() ucwords() vfprintf() vprintf() vsprintf() wordwrap() Returns a part of a string Compares two strings from a specified start position (binary safe and optionally case-sensitive) Replaces a part of a string with another string Strips whitespace from both sides of a string Converts the first character of a string to uppercase Converts the first character of each word in a string to uppercase Writes a formatted string to a specified output stream Outputs a formatted string Writes a formatted string to a variable Wraps a string to a given number of characters 3 5 Counts the number of times a substring occurs in a string 4 4 3 3 3 5 4 4 4 PHP String Constants PHP: indicates the earliest version of PHP that supports the constant. For standard DES encryption. 0 otherwise0 PHP CRYPT_STD_DES CRYPT_EXT_DES CRYPT_MD5 CRYPT_BLOWFISH HTML_SPECIALCHARS HTML_ENTITIES ENT_COMPAT ENT_QUOTES ENT_NOQUOTES CHAR_MAX LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_ALL . 0 otherwise Set to 1 if the MD5 encryption with a 12 character salt starting with $1$ is supported. Constant CRYPT_SALT_LENGTH Description Contains the length of the default encryption method for the system. 0 otherwise Set to 1 if the Blowfish encryption with a 16 character salt starting with $2$ or $2a$ is supported.

LC_MESSAGES STR_PAD_LEFT STR_PAD_RIGHT STR_PAD_BOTH .

PHP Operators This section lists the different operators used in PHP. Arithmetic Operators Operator + * / % Description Addition Subtraction Multiplication Division Modulus (division remainder) Example x=2 x+2 x=2 5-x x=4 x*5 15/5 5/2 5%2 10%8 10%2 x=5 x++ x=5 x-Result 4 3 20 3 2.Operators are used to operate on values. 5.y x=x%y Comparison Operators Operator == != <> > < Description is equal to is not equal is not equal is greater than is less than Example 5==8 returns false 5!=8 returns true 5<>8 returns true 5>8 returns false 5<8 returns true .5 1 2 0 x=6 x=4 ++ -- Increment Decrement Assignment Operators Operator = += -= *= /= .= %= Example x=y x+=y x-=y x*=y x/=y x.=y x%=y Is The Same As x=y x=x+y x=x-y x=x*y x=x/y x=x.

>= <= is greater than or equal to is less than or equal to 5>=8 returns false 5<=8 returns true Logical Operators Operator && Description and Example x=6 y=3 (x < 10 && y > 1) returns true || or x=6 y=3 (x==5 || y==5) returns false ! not x=6 y=3 !(x==y) returns true .

.else statement . Syntax if (condition) code to be executed if condition is true..use this statement to execute some code only if a specified condition is true if.elseif. Conditional Statements Very often when you write code. You can use conditional statements in your code to do this.else statement . The code is executed only if the specified condition is true.. The following example will output "Have a nice weekend!" if the current day is Friday: <html> <body> <?php $d=date("D"). in this syntax..use this statement to select one of many blocks of code to be executed The if Statement Use the if statement to execute some code only if a specified condition is true. if ($d=="Fri") echo "Have a nice weekend!". In PHP we have the following conditional statements:     if statement .else..use this statement to execute some code if a condition is true and another code if the condition is false if....Conditional statements are used to perform different actions based on different conditions. 6. you want to perform different actions for different decisions. ?> </body> </html> Notice that there is no ..use this statement to select one of several blocks of code to be executed switch statement . .

. Syntax if (condition) code to be executed if condition is true. } ... ?> </body> </html> If more than one line should be executed if a condition is true/false. if ($d=="Fri") { echo "Hello!<br />". echo "See you on Monday!". else echo "Have a nice day!".else statement to execute some code if a condition is true and another code if a condition is false. echo "Have a nice weekend!". if ($d=="Fri") echo "Have a nice weekend!". otherwise it will output "Have a nice day!": <html> <body> <?php $d=date("D"). Example The following example will output "Have a nice weekend!" if the current day is Friday. the lines should be enclosed within curly braces: <html> <body> <?php $d=date("D")... else code to be executed if condition is false.The if.else Statement Use the if.

elseif (condition) code to be executed if condition is true. Example The following example will output "Have a nice weekend!" if the current day is Friday... if ($d=="Fri") echo "Have a nice weekend!".elseif. Syntax if (condition) code to be executed if condition is true......elseif.?> </body> </html> The if. and "Have a nice Sunday!" if the current day is Sunday.else Statement Use the if. ?> </body> </html> . else code to be executed if condition is false.else statement to select one of several blocks of code to be executed.. elseif ($d=="Sun") echo "Have a nice Sunday!". Otherwise it will output "Have a nice day!": <html> <body> <?php $d=date("D").. else echo "Have a nice day!"..

PHP Switch Statement Conditional statements are used to perform different actions based on different conditions. Use break to prevent the code from running into the next case automatically. break. Example <html> <body> <?php switch ($x) { case 1: echo "Number 1". The default statement is used if no match is found. default: echo "No number between 1 and 3". break. case 3: echo "Number 3". } This is how it works: First we have a single expression n (most often a variable). break. default: code to be executed if n is different from both label1 and label2. The PHP Switch Statement Use the switch statement to select one of many blocks of code to be executed. The value of the expression is then compared with the values for each case in the structure. break. break. that is evaluated once. case label2: code to be executed if n=label2. the block of code associated with that case is executed. Syntax switch (n) { case label1: code to be executed if n=label1. case 2: echo "Number 2". If there is a match. .

} ?> </body> </html> .

2. There are two methods to create a numeric array. In the following example the index are automatically assigned (the index starts at 0): $cars=array("Saab". a variable will hold only one value. $cars2="Volvo".An array where each ID key is associated with a value Multidimensional array .PHP Arrays An array stores multiple values in one single variable.7. what if you want to loop through the cars and find a specific one? And what if you had not 3 cars. What is an Array? A variable is a storage area holding a number or text. Each element in the array has its own index so that it can be easily accessed. but 300? The best solution here is to use an array! An array can hold all your variable values under a single name. However. storing the cars in single variables could look like this: $cars1="Saab".An array containing one or more arrays Numeric Arrays A numeric array stores each array element with a numeric index. An array is a special variable."Toyota"). And you can access the values by referring to the array name.An array with a numeric index Associative array . In the following example we assign the index manually: . there are three kind of arrays:    Numeric array . which can store multiple values in one single variable. In PHP. $cars3="BMW". 1."Volvo". for example)."BMW". If you have a list of items (a list of car names. The problem is.

" and " . but shows a different way of creating the array: . " are Swedish cars. "Joe"=>34). When storing data about specific named values. Associative Arrays An associative array. $cars[2]="BMW". $cars[1] . echo $cars[0] . Example In the following example you access the variable values by referring to the array name and index: <?php $cars[0]="Saab". With associative arrays we can use the values as keys and assign values to them. $cars[1]="Volvo". ?> The code above will output: Saab and Volvo are Swedish cars. $cars[1]="Volvo". Example 1 In this example we use an array to assign ages to the different persons: $ages = array("Peter"=>32. $cars[2]="BMW". $cars[3]="Toyota".$cars[0]="Saab". each ID key is associated with a value. $cars[3]="Toyota".". a numerical array is not always the best way to do it. Example 2 This example is the same as example 1. "Quagmire"=>30.

$ages['Joe'] = "34".$ages['Peter'] = "32".". . $ages['Quagmire'] = "30". Example In this example we create a multidimensional array. $ages['Joe'] = "34". ?> The code above will output: Peter is 32 years old. echo "Peter is " . and so on. The ID keys can be used in a script: <?php $ages['Peter'] = "32". "Quagmire"=>array ( "Glenn" ). "Lois". Multidimensional Arrays In a multidimensional array. with automatically assigned ID keys: $families = array ( "Griffin"=>array ( "Peter". And each element in the sub-array can be an array. each element in the main array can also be an array. $ages['Peter'] . "Megan" ). $ages['Quagmire'] = "30". " years old.

" a part of the Griffin family?". $families['Griffin'][2] . The array above would look like this if written to the output: Array ( [Griffin] => Array ( [0] => Peter [1] => Lois [2] => Megan ) [Quagmire] => Array ( [0] => Glenn ) [Brown] => Array ( [0] => Cleveland [1] => Loretta [2] => Junior ) ) Example 2 Lets try displaying a single value from the array above: echo "Is " . "Junior" ) ). "Loretta". The code above will output: Is Megan a part of the Griffin family? ."Brown"=>array ( "Cleveland".

Function array() array_change_key_case() array_chunk() array_combine() Description Creates an array Returns an array with all keys in lowercase or uppercase Splits an array into chunks of arrays PHP 3 4 4 Creates an array by using one array for keys and another for 5 its values Returns an array with the number of occurrences for each value Compares array values. There are also specific functions for populating arrays from database queries.Complete PHP Array Reference For a complete reference of all array functions. and examples of use. There is no installation needed to use these functions. Installation The array functions are part of the PHP core. for each function! PHP Array Functions PHP Array Introduction The array functions allow you to manipulate arrays. PHP Array Functions PHP: indicates the earliest version of PHP that supports the function. go to our complete PHP Array Reference. The reference contains a brief description. and returns the differences 4 array_count_values() array_diff() array_diff_assoc() 4 Compares array keys and values. PHP supports both simple and multi-dimensional arrays. and returns the differences 4 .

and returns the matches Compares array keys and values. to an array Deletes the last element of an array Calculates the product of the values in an array 4 4 4 4 array_merge() array_merge_recursive() array_multisort() array_pad() array_pop() array_product() 4 5 . with a specified value. with an additional user-made function 5 check. with an additional usermade function check. and returns the matches Compares array keys. and returns the differences Compares array keys and values. with an additional user-made function 5 check. and returns the differences Fills an array with values Filters elements of an array using a user-made function Exchanges all keys with their associated values in an array Compares array values. and returns the matches Compares array keys and values. and returns the matches Checks if the specified key exists in the array Returns all the keys of an array 4 4 array_key_exists() array_keys() array_map() Sends each value of an array to a user-made function. with an additional usermade function check. and returns the differences 5 5 array_diff_ukey() Compares array keys. which 4 returns new values Merges one or more arrays into one array Merges one or more arrays into one array Sorts multiple or multi-dimensional arrays Inserts a specified number of items.array_diff_key() array_diff_uassoc() Compares array keys. and returns the matches 4 4 4 4 4 5 5 array_fill() array_filter() array_flip() array_intersect() array_intersect_assoc() array_intersect_key() array_intersect_uassoc() array_intersect_ukey() Compares array keys.

and returns the value of the removed element Returns selected parts of an array Removes and replaces specified elements of an array Returns the sum of the values in an array Compares array values in a user-made function and returns an array Compares array keys. and compares array values in a usermade function. and returns an array Compares array keys and array values in user-made functions. and returns an array Compares array values in a user-made function and returns an array Compares array keys. and returns an array Compares array keys and array values in user-made functions. and compares array values in a usermade function. and returns an array Removes duplicate values from an array Adds one or more elements to the beginning of an array Returns all the values of an array Applies a user function to every member of an array Applies a user function recursively to every member of an 4 4 4 4 4 4 array_slice() array_splice() array_sum() array_udiff() 4 4 4 5 array_udiff_assoc() 5 array_udiff_uassoc() 5 array_uintersect() 5 array_uintersect_assoc() 5 array_uintersect_uassoc() 5 array_unique() array_unshift() array_values() array_walk() array_walk_recursive() 4 4 4 3 5 .array_push() array_rand() array_reduce() array_reverse() array_search() array_shift() Inserts one or more elements to the end of an array Returns one or more random keys from an array Returns an array as a string. using a user-defined function Returns an array in the reverse order Searches an array for a given value and returns the key Removes the first element from an array.

array arsort() Sorts an array in reverse order and maintain index association Sorts an array and maintain index association Create array containing variables and their values Counts elements in an array. or properties in an object Returns the current element in an array Returns the current key and value pair from an array Sets the internal pointer of an array to its last element Imports variables into the current symbol table from an array Checks if a specified value exists in an array Fetches a key from an array Sorts an array by key in reverse order Sorts an array by key Assigns variables as if they were an array Sorts an array using a case insensitive "natural order" algorithm Sorts an array using a "natural order" algorithm Advance the internal array pointer of an array Alias of current() Rewinds the internal array pointer Creates an array containing a range of elements Sets the internal pointer of an array to its first element 3 asort() compact() count() current() each() end() extract() 3 4 3 3 3 3 3 in_array() key() krsort() ksort() list() natcasesort() 4 3 3 3 3 4 natsort() next() pos() prev() range() reset() 4 3 3 3 3 3 .

Constant CASE_LOWER Description Used with array_change_key_case() to convert array keys to lower case Used with array_change_key_case() to convert array keys to upper case Used with array_multisort() to sort in ascending order Used with array_multisort() to sort in descending order Used to compare items normally Used to compare items numerically Used to compare items as strings Used to compare items as strings. based on the current locale 4 PHP CASE_UPPER SORT_ASC SORT_DESC SORT_REGULAR SORT_NUMERIC SORT_STRING SORT_LOCALE_STRING COUNT_NORMAL .rsort() shuffle() sizeof() sort() uasort() Sorts an array in reverse order Shuffles an array Alias of count() Sorts an array Sorts an array with a user-defined function and maintain index association Sorts an array by keys using a user-defined function Sorts an array by values using a user-defined function 3 3 3 3 3 uksort() usort() 3 3 PHP Array Constants PHP: indicates the earliest version of PHP that supports the constant.

COUNT_RECURSIVE EXTR_OVERWRITE EXTR_SKIP EXTR_PREFIX_SAME EXTR_PREFIX_ALL EXTR_PREFIX_INVALID EXTR_PREFIX_IF_EXISTS EXTR_IF_EXISTS EXTR_REFS .

While Loops Loops execute a block of code a specified number of times. "<br />". $i++. we have the following looping statements:     while . Instead of adding several almost equal lines in a script we can use loops to perform a task like this. or while a specified condition is true. you want the same block of code to run over and over again in a row.loops through a block of code while a specified condition is true do. while($i<=5) { echo "The number is " .. Syntax while (condition) { code to be executed. } ?> .while . $i . PHP Looping . In PHP. or equal to 5.loops through a block of code for each element in an array The while Loop The while loop executes a block of code while a condition is true.loops through a block of code once. The loop will continue to run as long as i is less than. i will increase by 1 each time the loop runs: <html> <body> <?php $i=1.loops through a block of code a specified number of times foreach .8. and then repeats the loop as long as a specified condition is true for . } Example The example below defines a loop that starts with i=1. PHP Loops Often when you write code..

it will then check the condition. } while (condition). echo "The number is " . It will then increment i with 1. or equal to 5: <html> <body> <?php $i=1...</body> </html> Output: The The The The The number number number number number is is is is is 1 2 3 4 5 The do. Example The example below defines a loop that starts with i=1. } . "<br />". Then the condition is checked. $i . Syntax do { code to be executed. and write some output. do { $i++. and repeat the loop while the condition is true.while statement will always execute the block of code once. and the loop will continue to run as long as i is less than..while Statement The do..

For Loops Loops execute a block of code a specified number of times.while ($i<=5). } Parameters:   init: Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop) condition: Evaluated for each loop iteration. The for Loop The for loop is used when you know in advance how many times the script should run. ?> </body> </html> Output: The The The The The number number number number number is is is is is 2 3 4 5 6 The for loop and the foreach loop will be explained in the next chapter. PHP Looping . the loop continues. the loop ends. Syntax for (init. If it evaluates to TRUE. condition. . If it evaluates to FALSE. or while a specified condition is true. increment) { code to be executed.

The loop will continue to run as long as i is less than. } . or equal to 5. $i . Syntax foreach ($array as $value) { code to be executed. $i++) { echo "The number is " . increment: Mostly used to increment a counter (but can be any code to be executed at the end of the loop) Note: Each of the parameters above can be empty. Example The example below defines a loop that starts with i=1. i will increase by 1 each time the loop runs: <html> <body> <?php for ($i=1. or have multiple expressions (separated by commas). } ?> </body> </html> Output: The The The The The number number number number number is is is is is 1 2 3 4 5 The foreach Loop The foreach loop is used to loop through arrays. $i<=5. "<br />".

} ?> </body> </html> Output: one two three ."two". "<br />". Example The following example demonstrates a loop that will print the values of the given array: <html> <body> <?php $x=array("one". foreach ($x as $value) { echo $value .For every loop iteration. the value of the current array element is assigned to $value (and the array pointer is moved by one) . you'll be looking at the next array value."three").so on the next loop iteration.

In PHP. } PHP function guidelines:   Give the function a name that reflects what the function does The function name can start with a letter or underscore (not a number) Example A simple function that writes my name when it is called: <html> <body> . please visit our PHP Reference. there are more than 700 built-in functions. To keep the script from being executed when the page loads. Syntax function functionName() { code to be executed. A function will be executed by a call to the function. you can put it into a function.9. PHP Built-in Functions For a complete reference and examples of the built-in functions. Create a PHP Function A function will be executed by a call to the function. You may call a function from anywhere within a page. PHP Functions The real power of PHP comes from its functions. PHP Functions In this chapter we will show you how to create your own functions.

. inside the parentheses. A parameter is just like a variable.<br />". writeName("Kai Jim"). ?> </body> </html> Output: My name is Kai Jim Refsnes PHP Functions .Adding parameters To add more functionality to a function. " Refsnes. Example 1 The following example will write different first names. } echo "My name is ". but equal last name: <html> <body> <?php function writeName($fname) { echo $fname . writeName(). echo "My sister's name is ". } echo "My name is ". we can add parameters.<?php function writeName() { echo "Kai Jim Refsnes". writeName("Hege"). Parameters are specified after the function name.

" Refsnes" . My brother's name is Stale Refsnes. } echo "My name is ". ?> </body> </html> Output: My name is Kai Jim Refsnes."?"). ?> </body> </html> Output: My name is Kai Jim Refsnes.". My sister's name is Hege Refsnes. writeName("Stale"). echo "My sister's name is ". writeName("Kai Jim"."!"). writeName("Hege". My sister's name is Hege Refsnes! . echo "My brother's name is ".").echo "My brother's name is ". "<br />". Example 2 The following function has two parameters: <html> <body> <?php function writeName($fname. writeName("Ståle". $punctuation .$punctuation) { echo $fname .

add(1.My brother's name is Ståle Refsnes? PHP Functions . use the return statement.Return values To let a function return a value.$y) { $total=$x+$y. return $total. } echo "1 + 16 = " . Example <html> <body> <?php function add($x. ?> </body> </html> Output: 1 + 16 = 17 .16).

php": "welcome. like user input PHP Form Handling The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts. ?> years old.php" looks like this: <html> <body> Welcome <?php echo $_POST["fname"]. PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms. called "welcome. </body> </html> Output could be something like this: . ?>!<br /> You are <?php echo $_POST["age"].10. Example The example below contains an HTML form with two input fields and a submit button: <html> <body> <form action="welcome. the form data is sent to a PHP file.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> When a user fills out the form above and click on the submit button.

The user will then get the error messages on the same page as the form. 10. Browser validation is faster and reduces the server load. Example <form action="welcome. 100 characters).php" method="get"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> When the user clicks the "Submit" button. Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send (max.w3schools. The $_GET Function The built-in $_GET function is used to collect values from a form sent with method="get". You should consider server validation if the user input will be inserted into a database.com/welcome. The PHP $_GET and $_POST functions will be explained in the next chapters. the URL sent to the server could look something like this: http://www.1 PHP $_GET Function The built-in $_GET function is used to collect values in a form with method="get". Form Validation User input should be validated on the browser whenever possible (by client scripts).php?fname=Peter&age=37 .Welcome John! You are 28 years old. instead of jumping to a different page. This makes it easier to discover the error. A good way to validate a form on the server is to post the form to itself.

the value cannot exceed 100 characters. because the variables are displayed in the URL.2 PHP $_POST Function The built-in $_POST function is used to collect values in a form with method="post".ini file). 10. it is possible to bookmark the page.The "welcome. Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.php" method="post"> Name: <input type="text" name="fname" /> Age: <input type="text" name="age" /> <input type="submit" /> .<br /> You are <?php echo $_GET["age"].php" file can now use the $_GET function to collect form data (the names of the form fields will automatically be the keys in the $_GET array): Welcome <?php echo $_GET["fname"]. This can be useful in some cases. ?>. The $_POST Function The built-in $_POST function is used to collect values from a form sent with method="post". Note: However. ?> years old! When to use method="get"? When using method="get" in HTML forms. there is an 8 Mb max size for the POST method. Example <form action="welcome. by default (can be changed by setting the post_max_size in the php. Note: This method should not be used when sending passwords or other sensitive information! However. Note: The get method is not suitable for large variable values. all variable names and values are displayed in the URL.

$_POST. However.php The "welcome. Example Welcome <?php echo $_REQUEST["fname"]. because the variables are not displayed in the URL.php" file can now use the $_POST function to collect form data (the names of the form fields will automatically be the keys in the $_POST array): Welcome <?php echo $_POST["fname"]. When to use method="post"? Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.</form> When the user clicks the "Submit" button. ?> years old. it is not possible to bookmark the page.com/welcome. the URL will look like this: http://www. and $_COOKIE. ?>!<br /> You are <?php echo $_REQUEST["age"].w3schools. The PHP $_REQUEST Function The PHP built-in $_REQUEST function contains the contents of both $_GET. The $_REQUEST function can be used to collect form data sent with both the GET and POST methods. ?>!<br /> You are <?php echo $_POST["age"]. . ?> years old.

timestamp) Parameter format timestamp Description Required. Specifies the format of the timestamp Optional. like"/". Specifies a timestamp.Represents the day of the month (01 to 31) m . denoting the date and/or time at which a certain event occurred. PHP Date() Function The PHP date() function is used to format a time and/or date The PHP Date() Function The PHP date() function formats a timestamp to a more readable date and time. Default is the current date and time PHP Date() .Format the Date The required format parameter in the date() function specifies how to format the date/time. ". Other characters. or "-" can also be inserted between the letters to add additional formatting: <?php . can be found in our PHP Date reference.Represents a year (in four digits) A list of all the characters that can be used in the format parameter. A timestamp is a sequence of characters.". Syntax date(format.Represents a month (01 to 12) Y .PHP Advanced 1. Here are some characters that can be used:    d .

echo date("Y/m/d") .11 2009-05-11 PHP Date() . "<br />". echo "Tomorrow is ". ?> The output of the code above could be something like this: Tomorrow is 2009/05/12 .date("d")+1.0.Adding a Timestamp The optional timestamp parameter in the date() function specifies a timestamp.date("m"). The mktime() function returns the Unix timestamp for a date. "<br />". If you do not specify a timestamp. The Unix timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified.day.0.date("Y/m/d".05. Syntax for mktime() mktime(hour. echo date("Y-m-d") ?> The output of the code above could be something like this: 2009/05/11 2009.is_dst) To go one day in the future we simply add one to the day argument of mktime(): <?php $tomorrow = mktime(0. echo date("Y.date("Y")).d") .minute.month. the current date and time will be used.year.m.second. $tomorrow).

Note: These functions depend on the locale settings of the server! Installation The date/time functions are part of the PHP core. This option is used by date_sunrise() and date_sunset() Specifies the default longitude (available since PHP 5).sunrise_zenith "90.sunset_zenith "90.83" PHP_INI_ALL date. The reference contains a brief description. This option is used by date_sunrise() and date_sunset() Specifies the default sunset zenith (available since PHP 5). go to our complete PHP Date Reference.2333" PHP_INI_ALL date.default_longitude "35. for each function! PHP Date / Time Functions PHP Date / Time Introduction The date/time functions allow you to extract and format the date and time on the server.ini. Date/Time configuration options: Name date. This option is used by date_sunrise() and date_sunset() Specifies the default sunrise zenith (available since PHP 5). There is no installation needed to use these functions.83" PHP_INI_ALL . Runtime Configuration The behavior of the date/time functions is affected by settings in php.default_latitude Default "31. This option is used by date_sunrise() and Changeable PHP_INI_ALL date.Complete PHP Date Reference For a complete reference of all date functions.7667" Description Specifies the default latitude (available since PHP 5). and examples of use.

date_sunset() date. Function checkdate() date_default_timezone_get() date_default_timezone_set() date_sunrise() date_sunset() date() getdate() Description Validates a Gregorian date Returns the default time zone Sets the default time zone Returns the time of sunrise for a given day / location Returns the time of sunset for a given day / location Formats a local time/date PHP 3 5 5 5 5 3 Returns an array that contains date and time information 3 for a Unix timestamp Returns an array that contains current time information Formats a GMT/UTC date/time Returns the Unix timestamp for a GMT date Formats a GMT/UTC time/date according to locale settings Formats a local time/date as integer Returns an array that contains the time components of a Unix timestamp Returns the microseconds for the current time 3 3 3 3 gettimeofday() gmdate() gmmktime() gmstrftime() idate() localtime() 5 4 microtime() 3 .timezone "" Specifies the default timezone (available since PHP 5.1) PHP_INI_ALL PHP Date / Time Functions PHP: indicates the earliest version of PHP that supports the function.

14 Aug 2005 16:13:03 UTC) RFC 850 (example: Sunday. 14 Aug 2005 16:13:03 +0000) RSS (Sun. Constant DATE_ATOM DATE_COOKIE Description Atom (example: 2005-08-15T16:13:03+0000) HTTP Cookies (example: Sun.mktime() strftime() strptime() strtotime() Returns the Unix timestamp for a date Formats a local time/date according to locale settings Parses a time/date generated with strftime() Parses an English textual date or time into a Unix timestamp Returns the current time as a Unix timestamp 3 3 5 3 time() 3 PHP Date / Time Constants PHP: indicates the earliest version of PHP that supports the constant. 14 Aug 2005 16:13:03 UTC) World Wide Web Consortium (example: 2005-0814T16:13:03+0000) PHP DATE_ISO8601 DATE_RFC822 DATE_RFC850 DATE_RFC1036 DATE_RFC1123 DATE_RFC2822 DATE_RSS DATE_W3C . 14-Aug-05 16:13:03 UTC) RFC 1036 (example: Sunday. 14-Aug-05 16:13:03 UTC) RFC 1123 (example: Sun. 14 Aug 2005 16:13:03 UTC) RFC 2822 (Sun. 14 Aug 2005 16:13:03 UTC) ISO-8601 (example: 2005-08-14T16:13:03+0000) RFC 822 (example: Sun.

PHP Include File Server Side Includes (SSI) You can insert the content of one PHP file into another PHP file before the server executes it. This means that you can create a standard header. use the include() function: <html> <body> <?php include("header. PHP include() Function The include() function takes all the content in a specified file and includes it in the current file. or when you add a new page to your site. with the include() or require() function. and the script will stop These two functions are used to create functions. footers. To include the header file in a page. you can simply change the menu file (instead of updating the links on all your web pages).php". When the header needs to be updated. ?> <h1>Welcome to my home page!</h1> <p>Some text. If an error occurs. but the script will continue execution require() generates a fatal error. footer. or menu file for all your web pages. headers.</p> </body> </html> Example 2 Assume we have a standard menu file. The two functions are identical in every way. Server side includes saves a lot of work. you can only update the include file. or elements that will be reused on multiple pages. called "menu.2.php".php"). the include() function generates a warning. Example 1 Assume that you have a standard header file. called "header. but the script will continue execution. that should be used on all pages: . except how they handle errors:   include() generates a warning.

?> </div> <h1>Welcome to my home page.php">Tutorials</a> href="/references.php">About Us</a> href="/contact.php">Home</a> href="/tutorials. it will look like this: <html> <body> <div class="leftmenu"> <a href="/default.<a <a <a <a <a <a href="/default.php">About Us</a> <a href="/contact.php">References</a> <a href="/examples.php">Examples</a> <a href="/about.php">Examples</a> href="/about.</h1> <p>Some text. Here is how it can be done: <html> <body> <div class="leftmenu"> <?php include("menu.php">Contact Us</a> </div> <h1>Welcome to my home page!</h1> <p>Some text.php">Tutorials</a> <a href="/references.php">Contact Us</a> All pages in the Web site should include this menu file.php").php">Home</a> <a href="/tutorials.</p> </body> </html> If you look at the source code of the page above (in a browser).</p> </body> </html> .php">References</a> href="/examples.

include]: failed to open stream: No such file or directory in C:\home\website\test. the include() function generates a warning. ?> </body> </html> Error message: Warning: include(wrongFile. The require() generates a fatal error. echo "Hello World!".PHP require() Function The require() function is identical to include().php) [function.include]: Failed opening 'wrongFile. let's run the same example with the require() function.C:\php5\pear') in C:\home\website\test. but the script will continue execution.php on line 5 Warning: include() [function. and the script will stop. Error Example include() Function <html> <body> <?php include("wrongFile. .. <html> <body> <?php require("wrongFile.php").php").php' for inclusion (include_path='.php on line 5 Hello World! Notice that the echo statement is executed! This is because a Warning does not stop the script execution. except that it handles errors differently. Error Example require() Function Now. If an error occurs.

. ?> </body> </html> Error message: Warning: require(wrongFile.require]: Failed opening required 'wrongFile.php) [function.php on line 5 Fatal error: require() [function. because the script execution stopped after the fatal error.C:\php5\pear') in C:\home\website\test.require]: failed to open stream: No such file or directory in C:\home\website\test.php on line 5 The echo statement is not executed.php' (include_path='.echo "Hello World!".. because scripts should not continue after an error. It is recommended to use the require() function instead of include().

Starts at the beginning of the file Read/Write.3. Returns FALSE and an error if file already exists w+ a a+ x x+ . PHP File Handling The fopen() function is used to open files in PHP. Opens and writes to the end of the file or creates a new file if it doesn't exist Read/Append. Opens and clears the contents of file. or creates a new file if it doesn't exist Read/Write. The first parameter of this function contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened: <html> <body> <?php $file=fopen("welcome. ?> </body> </html> The file may be opened in one of the following modes: Modes r r+ w Description Read only. or creates a new file if it doesn't exist Append. Creates a new file. Starts at the beginning of the file Write only. Opens and clears the contents of file. Preserves file content by writing to the end of the file Write only. Creates a new file. Opening a File The fopen() function is used to open files in PHP. Returns FALSE and an error if file already exists Read/Write."r").txt".

and x mode! if (feof($file)) echo "End of file". //some code to be executed fclose($file). a.txt".txt"."r").Note: If the fopen() function is unable to open the specified file. it returns 0 (false). Example The following example generates a message if the fopen() function is unable to open the specified file: <html> <body> <?php $file=fopen("welcome. Note: You cannot read from files opened in w. ?> Check End-of-file The feof() function checks if the "end-of-file" (EOF) has been reached."r") or exit("Unable to open file!"). The feof() function is useful for looping through data of unknown length. ?> </body> </html> Closing a File The fclose() function is used to close an open file: <?php $file = fopen("test. .

Reading a File Line by Line
The fgets() function is used to read a single line from a file. Note: After a call to this function the file pointer has moved to the next line.

Example
The example below reads a file line by line, until the end of file is reached:

<?php $file = fopen("welcome.txt", "r") or exit("Unable to open file!"); //Output a line of the file until the end is reached while(!feof($file)) { echo fgets($file). "<br />"; } fclose($file); ?>

Reading a File Character by Character
The fgetc() function is used to read a single character from a file. Note: After a call to this function the file pointer moves to the next character.

Example
The example below reads a file character by character, until the end of file is reached:

<?php $file=fopen("welcome.txt","r") or exit("Unable to open file!"); while (!feof($file)) { echo fgetc($file); } fclose($file); ?>

PHP Filesystem Reference
For a full reference of the PHP filesystem functions, visit our PHP Filesystem Reference.

3.1 PHP Filesystem Functions
PHP Filesystem Introduction
The filesystem functions allow you to access and manipulate the filesystem.

Installation
The filesystem functions are part of the PHP core. There is no installation needed to use these functions.

Runtime Configuration
The behavior of the filesystem functions is affected by settings in php.ini. Filesystem configuration options: Name allow_url_fopen user_agent Default "1" NULL Description Allows fopen()-type functions to work with URLs (available since PHP 4.0.4) Defines the user agent for PHP to send (available since PHP 4.3) Changeable PHP_INI_SYSTEM PHP_INI_ALL

default_socket_timeout

"60"

Sets the default timeout, in seconds, for PHP_INI_ALL socket based streams (available since PHP 4.3) Defines the anonymous FTP password (your email address) PHP_INI_ALL

from

""

auto_detect_line_endings "0"

When set to "1", PHP will examine the PHP_INI_ALL data read by fgets() and file() to see if it is using Unix, MS-Dos or Mac lineending characters (available since PHP

4.3)

Unix / Windows Compatibility
When specifying a path on Unix platforms, the forward slash (/) is used as directory separator. However, on Windows platforms, both forward slash (/) and backslash (\) can be used.

PHP Filesystem Functions
PHP: indicates the earliest version of PHP that supports the function. Function basename() chgrp() chmod() chown() clearstatcache() copy() delete() dirname() disk_free_space() disk_total_space() diskfreespace() fclose() feof() fflush() Description Returns the filename component of a path Changes the file group Changes the file mode Changes the file owner Clears the file status cache Copies a file See unlink() or unset() Returns the directory name component of a path Returns the free space of a directory Returns the total size of a directory Alias of disk_free_space() Closes an open file Tests for end-of-file on an open file Flushes buffered output to an open file 3 4 4 3 3 3 4 PHP 3 3 3 3 3 3

from an open file Reads a file into an array Checks whether or not a file or directory exists Reads a file into a string Writes a string to a file Returns the last access time of a file Returns the last change time of a file Returns the group ID of a file Returns the inode number of a file Returns the last modification time of a file Returns the user ID (owner) of a file Returns the permissions of a file Returns the file size Returns the file type Locks or releases a file Matches a filename or string against a specified pattern Opens a file or URL Reads from an open file. with HTML and PHP tags removed.fgetc() fgetcsv() fgets() fgetss() Returns a character from an open file Parses a line from an open file. checking for CSV fields Returns a line from an open file Returns a line. until EOF. and writes the result to the output buffer Formats a line as CSV and writes it to an open file 3 3 3 3 file() file_exists() file_get_contents() file_put_contents fileatime() filectime() filegroup() fileinode() filemtime() fileowner() fileperms() filesize() filetype() flock() fnmatch() fopen() fpassthru() 3 3 4 5 3 3 3 3 3 3 3 3 3 3 4 3 3 fputcsv() 5 .

fputs() fread() fscanf() fseek() fstat() ftell() ftruncate() fwrite() glob() Alias of fwrite() Reads from an open file Parses input from an open file according to a specified format Seeks in an open file Returns information about an open file Returns the current position in an open file Truncates an open file to a specified length Writes to an open file Returns an array of filenames / directories matching a specified pattern Checks whether a file is a directory Checks whether a file is executable Checks whether a file is a regular file Checks whether a file is a link Checks whether a file is readable Checks whether a file was uploaded via HTTP POST Checks whether a file is writeable Alias of is_writable() Creates a hard link Returns information about a hard link Returns information about a file or symbolic link Creates a directory Moves an uploaded file to a new location 3 3 4 3 4 3 4 3 4 is_dir() is_executable() is_file() is_link() is_readable() is_uploaded_file() is_writable() is_writeable() link() linkinfo() lstat() mkdir() move_uploaded_file() 3 3 3 3 3 3 4 3 3 3 3 3 4 .

parse_ini_file() pathinfo() pclose() popen() readfile() readlink() realpath() rename() rewind() rmdir() set_file_buffer() stat() symlink() tempnam() tmpfile() touch() umask() unlink() Parses a configuration file Returns information about a file path Closes a pipe opened by popen() Opens a pipe Reads a file and writes it to the output buffer Returns the target of a symbolic link Returns the absolute pathname Renames a file or directory Rewinds a file pointer Removes an empty directory Sets the buffer size of an open file Returns information about a file Creates a symbolic link Creates a unique temporary file Creates a unique temporary file Sets access and modification time of a file Changes file permissions for files Deletes a file 4 4 3 3 3 3 4 3 3 3 3 3 3 3 3 3 3 3 PHP Filesystem Constants PHP: indicates the earliest version of PHP that supports the constant. Constant Description PHP .

GLOB_BRACE GLOB_ONLYDIR GLOB_MARK GLOB_NOSORT GLOB_NOCHECK GLOB_NOESCAPE PATHINFO_DIRNAME PATHINFO_BASENAME PATHINFO_EXTENSION FILE_USE_INCLUDE_PATH FILE_APPEND FILE_IGNORE_NEW_LINES FILE_SKIP_EMPTY_LINES .

Look at the following HTML form for uploading files: <html> <body> <form action="upload_file. } else . Create an Upload-File Form To allow users to upload files from a form can be very useful. Create The Upload Script The "upload_file. there will be a browse-button next to the input field Note: Allowing users to upload files is a big security risk. PHP File Upload With PHP.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> Notice the following about the HTML form above:   The enctype attribute of the <form> tag specifies which content-type to use when submitting the form. it is possible to upload files to the server. to be uploaded The type="file" attribute of the <input> tag specifies that the input should be processed as a file.php" file contains the code for uploading a file: <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . "multipart/form-data" is used when a form requires binary data. like the contents of a file. "<br />".4. Only permit trusted users to perform file uploads. For example. when viewed in a browser. $_FILES["file"]["error"] .

"Size: " . Restrictions on Upload In this script we add some restrictions to the file upload. $_FILES["file"]["tmp_name"]. "size". Like this:      $_FILES["file"]["name"] . $_FILES["file"]["type"] . "Stored in: " . The user may only upload . echo "Size: " .the name of the temporary copy of the file stored on the server $_FILES["file"]["error"] . } else { echo "Upload: " . ($_FILES["file"]["size"] / 1024) . "Type: " . "<br />". "tmp_name" or "error".the type of the uploaded file $_FILES["file"]["size"] . echo "Type: " .the error code resulting from the file upload This is a very simple way of uploading files.the name of the uploaded file $_FILES["file"]["type"] . $_FILES["file"]["error"] . you should add restrictions on what the user is allowed to upload. " Kb<br />".{ echo echo echo echo } ?> "Upload: " . "type". $_FILES["file"]["name"] . By using the global PHP $_FILES array you can upload files from a client computer to the remote server. For security reasons. "<br />". "<br />". ($_FILES["file"]["size"] / 1024) . "<br />". $_FILES["file"]["type"] . $_FILES["file"]["tmp_name"]. " Kb<br />". $_FILES["file"]["name"] . "<br />". } } else { echo "Invalid file".gif or . } . The first parameter is the form's input name and the second index can be either "name".the size in bytes of the uploaded file $_FILES["file"]["tmp_name"] .jpeg files and the file size must be under 20 kb: <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Error: " . echo "Stored in: " .

" Kb<br />". $_FILES["file"]["name"]).?> Note: For IE to recognize jpg files the type must be pjpeg. $_FILES["file"]["name"] . echo "Size: " . $_FILES["file"]["name"]. ($_FILES["file"]["size"] / 1024) . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . "<br />". echo "Temp file: " . The temporary copied files disappears when the script ends. "upload/" . if it does not. "<br />". "<br />". $_FILES["file"]["type"] . for FireFox it must be jpeg. " already exists. "upload/" . } else { move_uploaded_file($_FILES["file"]["tmp_name"]. To store the uploaded file we need to copy it to a different location: <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["tmp_name"] . $_FILES["file"]["error"] . if (file_exists("upload/" . it copies the file to the specified folder. echo "Stored in: " . } } } else { echo "Invalid file". "<br />". Saving the Uploaded File The examples above create a temporary copy of the uploaded files in the PHP temp folder on the server. ". } ?> The script above checks if the file already exists. Note: This example saves the file to a new folder called "upload" . echo "Type: " . } else { echo "Upload: " .

Example 2 You can also set the expiration time of the cookie in another way.5. Syntax setcookie(name. Each time the same computer requests a page with a browser. value.. Note: The setcookie() function must appear BEFORE the <html> tag. it will send the cookie too. How to Create a Cookie? The setcookie() function is used to set a cookie. It may be easier than using seconds. you can both create and retrieve cookie values. <?php . use setrawcookie() instead). PHP Cookies A cookie is often used to identify a user. we will create a cookie named "user" and assign the value "Alex Porter" to it. Example 1 In the example below. What is a Cookie? A cookie is often used to identify a user. "Alex Porter". We also specify that the cookie should expire after one hour: <?php setcookie("user". time()+3600). path. A cookie is a small file that the server embeds on the user's computer.. expire.. With PHP. Note: The value of the cookie is automatically URLencoded when sending the cookie. domain).. ?> <html> . and automatically decoded when received (to prevent URLencoding.

. // A way to view all cookies print_r($_COOKIE). we retrieve the value of the cookie named "user" and display it on a page: <?php // Print a cookie echo $_COOKIE["user"]. $_COOKIE["user"] . ?> </body> </html> ... How to Retrieve a Cookie Value? The PHP $_COOKIE variable is used to retrieve a cookie value. "Alex Porter". setcookie("user".. "!<br />". ?> <html> . else echo "Welcome guest!<br />". In the example below. ?> In the following example we use the isset() function to find out if a cookie has been set: <html> <body> <?php if (isset($_COOKIE["user"])) echo "Welcome " . In the example above the expiration time is set to a month (60 sec * 60 min * 24 hours * 30 days).$expire=time()+60*60*24*30. $expire).

"".php" file like this: <html> <body> Welcome <?php echo $_POST["name"].php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> </body> </html> Retrieve the values in the "welcome. time()-3600). ?> What if a Browser Does NOT Support Cookies? If your application deals with browsers that do not support cookies.<br /> You are <?php echo $_POST["age"]. you will have to use other methods to pass information from one page to another in your application. The form below passes the user input to "welcome.How to Delete a Cookie? When deleting a cookie you should assure that the expiration date is in the past. ?> years old.php" when the user clicks on the "Submit" button: <html> <body> <form action="welcome. ?>. </body> . One method is to pass the data through forms (forms and user input are described earlier in this tutorial). Delete example: <?php // set the expiration date to one hour ago setcookie("user".

</html> .

78( .2504:...78   %0...78    884...2508908.:0  0389473/.94.884.-4:9850.8 3..3:207...9..8349.883.78 ( .7.08.3/.250 -:9848.4/0.9.0.077.20.70$0/8...-.3/3/0 55 .3:8090... !0907 ":.3/ .77.- .890-089.2500:80..80.:08.78( .77...- ..1.41.3.78('4.089490/11070395078438 .78 ($.78(%449...80.20/.3/'4.270 40  ...77./1107039..08890.884. ..250 3980.90/9.0.78(%449.77.78 ($.9..9390.4 .:08 ..808.3.94/49  9.250 39014430.4 .4.78('4.884... 0.883.3.77.04:95:9 $.9. 0.:0894902  .77. ...:08-70107739490.70.250 %80...-0...77.20.70$0/8.4.78( .-4.08..

3-0.4/0..208...002039 3908:- .. .8830/08 1.77.70.3. 9..08 40 (  0.2500.270 (  .:942.84-0.   7113.9.759 55 .270 (  .3-0:80/3.3/8443  .0020393902.77.77. 3/0.2:9/203843...90.250 3980.2:9/203843.77.8 3.77.08 !0907 ( 0.4!09078 .3.08 40 ( %008.784/   %0.04:95:9 !090780..77.08 ":.3..-4. 0...77.8.   033   .270.3.77.77.3   ":.77.08 ":..784/    :9/203843.08 !0907 ( .   !0907  48  0.08 !0907 ( .

   0.:0174290..48 1.-4.79419071131.2  .  :347     %0.79419071131..743.3.04:95:9 80.    (0.  7113(77.3/ (47099.2 %0.77.3.3   ":.0.    (033   743(77.5.250 09897/85.-4.270(77.77.0.0 0.77.5.4/0.830.3/  47099.208 7113 ((  .. (:347    .    (!0907 (48 (0.-4.04:/4409817990394904:95:9 77.

-. .77.9438147 545:.3974/:.81742/..77..44:942.3.3.9903:2-07414. 08.77.0 47.77.908.9438   !!77.0784341!!9.3.943300/0/94:8090801:3.08  .943 %0.1:3.:08 #09:738.3/709:73890/110703..943  :3.77.*.30*0*.75943 70.708.250841:80 1470.77.77.908.3/0.908900.84850..1.3/.0..:7703..77..77.42-30  70.77.77.8  !!8:554798-498250.14708.394.35:.425090!!77.1:3.943 !!77..7089.8 %070.:08 .4:39*.081470.#010703..708.77.1:3.70.#010703.3.77.77.80 $598.1:3.77.794190!!.34907147  98.8047:5507.3/2:9 /203843.4250907010703..0  %07010703..:3   .9438 4944:7.083407..3.77.8 !!     .90.:3841.9438.77.705.1:3.:08 .93.*..041.*.-701/08..9438 !!3/..  425.9438.806:0708   389.98:554798901:3.*/11*.08.80 .9438 !!77.884.-:83430.3/..:3.08  .:0 425.:08  ..439.3/709:73890/110703.9..9.:3.77. #09:738.77..*.943 .38.75943 .77.943 %0. 425090!!77.470 %070834389.*/11   .77.77.

:78./01:3.77.*545    ..089907.77..3..77.708.3/.08 8..8190850.*390780.77.:08 9.     .:08 ..77.90/. ..08 425.77.3.:807 2..*2.77.*5..:041.3.9.77.77.0.08 425..  .708.77.*2:98479 .*/11*:0  425.708.900841.08.3.*1  .9.:807 2.9*:0  425.//943..10/00898390.77.943  ..3/709:738902.*390780. 425.:807 2. ..3.77./    .77.77. .77. .08.77.3/709:738902.*1907 ./01:3.0 .77.*574/:.*/11*0  425.77.9.77.//943.10/3:2-07419028 9..708.//943.884.:08 0708430472470.  .884.77..77.08 425.3/709:73890/110703.943  ./01:3.77.08 425.:08 9078002039841.3.77.9  .9  .9.77.9*:.*15   .3..77..08 9.77.943 .08 .3. 0708430472470.3.77.3/709:73890/110703.0.10/.708.943 .77.08.:807 2./01:3. #09:738. 0090890.77.3.77. .:083.8394430.9*.708.77.850.3/..884.9.0.9.3/709:738902.08 .77.   .77.*08 .943.850.8394430.//943./01:3.*2070*70.77. .3/.08        .3/709:73890/110703. $47982:950472:9 /203843.*390780.708.3.*390780.77.:0  94.*390780.94190.*0*0898 ./01:3.884.3..:807 2.*/11*:.943.9*0   .77.90890574/:.:.77.77.08 0.08   .*2070  .8 380798.0.94.:08 9.708.3/709:738902.77.:83.5    $03/80.08 9.:083.308.:08 .77.8900203941.  709:73830.3/709:738902.77.:807 2.77.

:807 2.10/002039841..   .94370.884.:807 2..*70.3.:0.77.:08 ..        .943.708.77.08850.77.3.*:36:0 . #09:738.708.147.77. #024.0 .3.943940.77. #024.943 .*8..:081742.          .3/./0 1:3.3  .../0 1:3.77.*7..3. #09:738908:24190. 5508.90.078047/07 $0.9  425. //843047247000203989490-033341.. 425.708..3/42081742.:807 2. 5508.3/709:738..77.  .39070.:78.08.77.77.3.77.*:390780..3/709:738  .0 .08/:5.77.3/709:738  .3/709:738.:0841.*:/11*:..77.3/705.*:/11*.77.. 425.*. .77.*5:8 .:083.0940.*.   .:8071:3.77.884.77.:8071:3.708.9*:. #09:7384304724707.77.708.*:390780./01:3. #09:738.9438 .77./01:3.0 .77.77..3/709:738.77.77. 425..07202-0741.943 #09:738.3/709:73890 .3.77.77.3.425.:807 /0130/1:3.:083.*:/11        425.0780 .3..*819     .3.77.089017890020391742.77.8.77.77.3.:083:807 2.77.9*.884..03.3/.:083.77.0/002039 #09:738800.77.3/709:738.77.77.943.  .  .77.*8:2 .708.08 .08.:041907024.77.3.77.884.3.77..708.77.3/. ..0  .7.:083.77.*:390780.3.77.*70./01:3.79841.3/  3807984304724700020398949003/41.*80.8973 :83.77.3/...77.:78.08.08 .77.*:3819 . 425.77./01:3.:083:807 2.3.08.943 .3.77.3.77.77.*.3.3/709:738900 #024.*85.3.7.90.:807 2.*70/:..90/5.708.07202-0741.:083.77.77.3.9438 ..425.

.3.9  3*.77.3/2.77.77.3.884.3 .. .3.9:7.39.9 #09:73890.77.77.77.3/.77.3.77.7.-08.3.90.10/.. $4798.30 70809             ..7... 09..:05. $0989039073.77.89002039 254798.3.4:39 .33.54390741.3.77.77. 03/      097..30410020398 $0989039073.4792 /.77..47/07.77..908.-0370.54390741.03.09039073.078047/07.078047/07 $4798.:83.:7703982-49.3.-0839490.77.:77039  #03/89039073.3.:770390020393.9.-08.:770390.7.:08 4:39800203983.370..47/07 . 475745079083. 7.3.3.:77039 0.. 0         78479 8479 89    3.98479 309 548 570.3.4792 $4798.9 .71742. $4798..-01742.:83.808479  3.3/2.3.439.8479         .543907 70.77.39.9:7.78479 $4798..77. ...:008983.3.08.77..80380389.54390741.3.850.81.7.439.943 $4798..77.77. 0..3/907..77.841.77..33/0.9498.943 70.3.01742.425.884.34-0.94981789002039   .-0 8838.3.8190070.33.3.33/0 . #09:73890.77.

709028.425.943 $4798.841.*.77.7090283472.43.078047/07 $:1108.370..943.80/4390.889738 &80/94. ..39  4389.77..39 $* # 08.77.80 94.943 $4798.77.:807 /0130/1:3.-08:83.:807 /0130/1:3.943      8:110 8041 8479    :.3.7090283:207.3.77.75943 !! &80/9.-.30*0*.77.39.3.7089.4389.8.079.425.3/2.77.0894  407.78479  $4798.80 94.43...98:55479890.*2:98479 9484793/08.8479  :8479 :8479       !!77.425.80 &80/9.9.0        $*&!!# $ #%*$ $ #%*$ $ #%*#&# $ #%*&# $ #%*$%# $ #%* *$%#  &%* #  .079.3.80 &80/9.03/347/07 &80/9.*.4:39  $4798. $4798.77. &80/94.425.889738 -.:08:83..77.77.0894  :5507.884.30*0*.4389..0784341!!9.3.:807 /0130/1:3.. &80/94.03/347/07 &80/94.77.*2:98479 9484793.3 3/0.908900.77.:77039 4.3.398 !!3/...709028..

 &%*#&#$' %#* '##% %#*$! %#*!#*$ %#*!#* %#*!#*' %#*!#**$%$ %#**$%$ %#*#$                                   .

//380.:90.10/3:2-07419208 1470.4/0 4:. !!4453 04458 445800.10/.4459.0020393.41.0 . 0 .80-0.43/943897:0  $39.4393:0947:3..33.41.9..41.41.3:804458945071472. 4458974:.843.07.8.3.10/.920904457:38 92 -4/  55  0    0.9890445.4/01470.850.43/943897:0 /4 0 4458974:.8098  3!! 0.74  3890.-4.0901443445389.4/00.989.-4.  %00445 %0044500.70.41.7989 %0445.4%03:2-078  -7.4/00.250 %00.4/094-000.-4.3083. 850.-4.4/0.39908.850.4/043.07..94 3.7590..-4.41.:90/ < .43/943897:0 147 4458974:.250-04/01308.10/3:2-07419208 470./41.88088 9.77.20-4.43/943897:0  !!4458 1903034:790.843.4/0947:34.3 4706:..4/0..07.-4.9020398 O O O O 0 4458974:.850.10/ .:908..3/9037050.850.3/4..41.248906:.8.43/943   .

   <  .

 .

-4/ .

902039 %0/4 089..250-04/01308.843.4%03:2-078  -7. /4  .43/943  .3/90445.41.90.250 %00.990445090.902039.0.4459.4/094-000.0/ .:90/ < 0 .0.989.800.43/943  .3/7050.43/9438.:9090-4.94 92 -4/  55  /4    0.880889.92 :95:9 %03:2-078 %03:2-078 %03:2-078 %03:2-078 %03:2-078   %0/4 0$9.7020399 .3 47 06:.4393:0947:3.3/7908420 4:95:9 %0390.43/943897:0  $39.7989 99033.0 9903.4/043.

 < .

0     .

-4/ .

.7.39208908.850..43/943897:0  %0147445 %01474458:80/034:343.209078 O O 39489:80/94809.445907.90894%#& 90445..75984:/7:3  $39. 147 39.:90/ < !.5907     !!4453 474458 445800.042.0.41.850.90/1470.10/ ..3./.4/0.990-0333 4190445  ..445-005.943 190.702039   .4:3907 -:9.:90..3..-4.4/094-000.3-0.:..4393:08 19 0.43/943..:.43/9433.:.3/901470.10/3:2-07419208 470.:90/43.30/390309.4/094-000.90894$ 9044503/8  .92 :95:9 %03:2-078 %03:2-078 %03:2-078 %03:2-078 %03:2-078 %0147445.

41905.989..4%03:2-078  -7.4:3907 -:9.843..O 3.7.250-04/01308.-4.7989 %0445.209078.702039489:80/943..80-0.990 03/4190445  490.4393:0947:3.3 4706:..:90/.3.88088 9.920904457:38 92 -4/  55 147    0..3-00259 47.422.7.90/- .02:950057088438 805.702039.0.8  .3-0.70.250 %00..4459.94 3.4/094-000.

 <   .

-4/ .

.:0   .4/094-000.4458:80/94445974:. 1470.8..445 %01470.8  $39.:90/ < .. .92 :95:9 %03:2-078 %03:2-078 %03:2-078 %03:2-078 %03:2-078   %01470...77.77.

 92 -4/  55 .:0  .8.77.943 90. 430 94 9700  1470.07445907..77.4459.77.4.:0 -7...:0   0..8830/94.0/-430  844390309445907.03.990309..:77039.250 %014430.250/0243897.77.908. .943 4: -0443.77.470.:084190.0020398.:0 .3/90. 543907824.:04190.9573990....

 <   .

-4/ .

92 :95:9 430 94 9700           .

4250907010703...1:3.9439.9901:3. 1:3.0   70.3.943  4:2.0.04.9438 398.5. !!:3.943 1:3.389.9431742.9433.200398.9790823.35:99394.4/094-000.943/408 %01:3.0990747:3/078.250 82501:3.7591742-0300.!!:3..59070844:494.9438  3!! 9070..:90/03905..9438  %4005908.943:/0308 O O .1:3.943  1:3.470 349..:90/ <  !!1:3..70..20  .97010.209.943.80.7024709.:90/-.42081742981:3.94901:3.9438 50.9438 47.9438 %070.943-000.0/ 92 -4/ .904:7431:3.0   !!:3.943./8 4:.98.894:7!!#010703.3:2-07  .0901:3.3 -:9 31:3..94901:3.90.307093.9431:3..540741!!.799.943-000.943  $39..9438  !!:9 3:3.:90/-.25084190-:9 31:3..20.3/0.

2#018308 <  0.208 790.4. 55 1:3.20    .20   0.43.943790.

-4/ .

209078.994.20 #018308 -7.250790/110703917893.7.209078 5.92 :95:9 3.413..893.943790.7.-0  !.7.3.20 13.2#018308   !!:3.209078:890.70850..//5.209078 %4.7.1:3.//24701:3.9433.208 -:906:..1907901:3.20   0.943.70390808  .20 92 -4/  55 1:3.943 0.9438 //35.10/.208.250 %014430.7.20 38/0905..

488907 83.208 790.20 00  .2  0.20 .208 790.43. <  0.

0    .0.208 790.20 $9.4-74907 83.

-4/ .

943 -7.20800#018308  -74907 83.20 5:3.92 :95:9 3.7.208.413.2#018308  88907 83.8945.208$9.943   0.20 #018308 5:3.9:.209078 92 -4/  55 1:3.20 13.9:.0#018308  .943790.943.250 %014431:3.

43.488907 83.20 .2    0.20 00   0.208 790. <  0.208 790.20 $90     .208 790.4-74907 83.

-4/ .

20800#018308 .92 :95:9 3.208.2#018308  88907 83.

208$90#018308   !!:3..:0 :8090709:7389.4  .//     949.250 92 -4/  55 1:3.:08 %409.  709:73949.943..943709:73.902039  .9438 #09:73.-74907 83.1:3.. <  0.//      .

-4/ .

92 :95:9          .

:942.9431742 14728 0:80735:9 !!472.3/*! $%.420 552094/5489 .70:80/9470970.-0..9.003/0.-08.-0944:7!!8.3%147299435:910/8.3/!!89.2013.9...7.399394349.31472002039 3.3%5. !!4728.7598  .9430.20.439..3/.3/3 %0248925479..250 %00.38.2035:99509093.031472..250-04.0.3/&80735:9  %0!!*%.8:-29-:9943 92 -4/  1472.39%14728.

20. 035:99509093.0.

 35:99508:-29.

 .

1472  .

-4/ .

3/.420550.0/0..!! 10 .:807184:9901472.43908:-29-:9943 901472/.4*! $%13.420 55448098 92 -4/  0.9.8803994..-4.420 55 0.92 03.0.20(-7.

 4:.784/   .4*! $%.70550.0(0.

-4/ .

4:/-0842093098 .92 :95:9.

80 44/..07.0843908.3/70/:.20.9438:80/94.8-0940.1472803992094/09  31472.94380391742.943190:80735:9-0380790/394.//7088-.8901472 %82.0 %0 :8079030990077472088.40./.9078  .2013.07 9007747     !!*%:3./.943 &80735:984:/-0./41:25394.943 %0-:9 3*%1:3.24:394131472.147292094/09  %0*%:3../11070395.30/390309.90.9438:80/94.7 .9430.4.0./...7598 74807 .700..59078   472'.94 ./  4:84:/.94394803/ 2.80794/8.82984390.90/4390-74807030.14724390807.3/*! $%1:3.07430 9-0/85.9.42043 4:.7.074.420 552094/09 .94381.0./.784/  %0!!*%.0890.40./.0398..9.250 1472.  ./.438/07807.0/390 -74807 8.2035:99509093.205.0890807.8907.9...-.:081742..075488-0 -..3/.:083.078945489901472949801 3890.9438-005.1472990%2094/8.943 %0-:9 3*%1:3.

20.0. 035:99509093.

 35:99508:-29.

 .

890$:-29-:9943 90&#80399490807.1472 0390:807..4:/44842093098 995.07.

.

448 . 8.42.

20!0907 .0.0 .420 5513.

.91472/. 903.9.%00.  0.40..20( -7.77.420550.:942.94394.20841901472 10/8.4*%13.334:8090*%1:3.9.-09008390*%.420 5510.

420 552094/5489 .9.1472990! $%2094/83.2013.20.3 -0:801:38420..00/  .943 %0-:9 3*! $%1:3.9.70..808  490%0092094/83498:9.-03...7.40.147292094/5489  %0*! $%:3.8-09449078.70/85..07 -0.-0147.3-0..:0890...7..031472.33490.0/390&#  490%82094/84:/349-0:80/03803/35.9078      !!*! $%:3.9438:80/94.:8090.784/   0394:802094/09 03:832094/093%14728 ..2035:99509093.8342984390 .70/85.943 %0-:9 3*! $%1:3.208.:08.07 90708.7.94394803/  49040.7905..0/390&# 985488-094-442.24:394131472.94380391742.-0..40.0 %8.7.4*%. 4:..0(0.3/.3/.-08.:083.8014790! $%2094/ -/01.3-2.:0.:9 .30/- 80993905489*2.:081742.70550.1472803992094/5489  31472.*8039055 310  ...9430.8847/847490780389..250 1472..9438:80/94..943 40.

0. 035:99509093.20.

 35:99508:-29.

 .

.

1472 0390:807..890$:-29-:9943 90&#44098 995.

.

448 . 8.42.

  0.91472/.20841901472 10/8.420550.:942.420 55 %00.77. 903.0.-09008390*! $%.4*! $%13..40.334:8090*! $%1:3..420 5510.94394.9.9.20(-7.

0   %0!!*#"&$%:3.4*! $%.94394803/  40.24:394131472.80399-4990%.439.4*#"&$%13.3/.-08. 4:.8342984390 .7905.9.20(-7..943 %0!!-:9 3*#"&$%1:3..07 -0.943.3/! $%2094/8  .3890.70349/85..:8090.94380391742.3-0:80/94.70550.439039841-49*% *! $% .91472/.7.40.8-09449078.1472990! $%2094/83.784/    0394:802094/5489 31472.3/*   %0*#"&$%1:3.943.420550.0/390&# 983495488-094-442.250 0.0(0.

 4:.70550.4*#"&$%.784/      .0(0.

9438:80/941472..920.9.!!/.3.943 %0!!/.90 :3.3/.0/    !!.90 1:3.

943 %0!!/.2594.90 :3.90./.90 %0!!.92089.90 1:3.041.258.90.806:03.7.3/.247070...-0/.9431472.3/920  92089.47/.98.9078 /0349390/.

:9890.90.92089.25 01.943850.90 1472.25 5943.990..95.20907390/.20907 1472..7.7.9 92089. $50.9 92089.3/920 !!.90  472.9.079.25   08.108.75943 #06:70/ $50.47920.1084941472.990/.30.039 4.90 1:3.9419092089. /..90.25   !.:77039/.108901472.90 %0706:70/1472.:770/  $39.

3-0:80/ O O O / #05708039890/.9.7 314:7/98  8941.7.20907 .7..9078 0.2439 94   #057080398.3-0:80/3901472.0  907..7..0.3-014:3/34:7!!..95.708420.920  070..90789..90 7010703...90..41902439 94  2 #057080398.90789.9.7.

 1472.3.993 55 .//.//943..84-0380790/-090039009907894.   47 .

0.90 .4/.

2.

/  -7.

90  2 /  -7.4/. 0.

 0.4/.90  2 /   %04:95:94190.-4.4:/-0842093098  .4/0.0.

.

108.7    % .25147.//4309490/.           !!.1472920  2920 4:7 23:90 80.439.255.43/ 2439 /.92089.90.20907390/.7:2039412920  55 94247742920 /.943709:73890&392089.90  0.92089.%2089.7. 0.25 14:/4349850.25 %045943.:77039/. 92089.25.7 8*/89  %44430/.90  %0&392089.4%4247748 /..43/8-0900390&354.10/  $39./.943850.90 .90 /  /.3901:9:700825.3:.38903:2-074180.90 2 /.25 90.90 1:3. .1.3/90920850.3/920-0:80/  %02920 1:3.90  //3.

2.

0.4/0./ 9424774    %04:95:94190.4:/-0842093098 %4247748 .-4.

.

   .

90.75943 .38.439.90#010703.-701/08..3/0.425090!!.0 47..4250907010703.425090!!.943 !!.0  %07010703.041.90#010703.1:3.0.901:3.9438 4944:7./.250841:80 1470.

9438 !!.90.%20:3.

943 %0/.%203974/:.90.

9438/0503/43904.08099384190807.07  490%0801:3.9201:3.3/1472.943 %0/.07  389.90.44:94097.9.3/9204390807.9438...90.990/..

9201:3.9438.943 %0-0.794190!!.474190/.90...470 %070834389.943300/0/94:809080 1:3.705.9438   #:3920431:7.

90.90/-809938355 3  .9201:3.110.94388.

.90*8:3809  .90 8:3809*039   !!** ..3/ !!** /..:9*.0!! %8459438 :80/-/.-0 !!** 83.-083.75943 $50.-083.:9 08.:98:3780039 .90*8:3780 .10890/01.3//.-0 !!** /.943459438 .10890/01...-0 83.3//.90 /01.90*8:3780 .20 01.0!! %8459438 :80/-/..:9*439:/0   $50.99:/0   /.99:/0 .:9.30.%20.431:7.0!! %8459438:80/- /..90*8:3780 ..:98:3809039 ...90*8:3809  $50..90 8:3780*039   /.3/ /.90 /01.10890/01.90*8:3809  $50.10890/01.90*8:3780 .0!! %8459438:80/- /..:9439:/0 .

0!!     !!.:9920430 .-0 !!** 83.90 920430  $50./..10890/01..90.90*8:3809  /..

.98:554798901:3./.0784341!!9.03/...%20:3.:9920430 #09:73890920418:3780147.908.3/.7047.0.90 08.7089.:9920430 $09890/01.943  :3.9438 !!3/.90 #09:73890/01.908900./.943 .75943 '.

..4.943 #09:73890920418:3809147.03/..

4.920.4.98.943 472...

%.90*/01.9.90      09/.&392089.25 #09:738.77.:9*920430*09 /.98.90  #09:738.90*8:3780 /./.90*8:3809 /.3/92031472.3.90 !!        /.38/.:7703992031472.9.943  147.439.90.439.9.:9*920430*809 /.3.9.77.38.943 472.90*/01.

90.&%/.

920 #09:73890&392089.90 472.%.25147.%/.98.

&%920.

920.47/3944..98.90..4../.0 809938 472..

74920  .90   4.:77039920  2.  &392089.9.9.25 #09:738902.42543039841. 2/.839007     0992041/.920  #09:738.90..43/814790.77.3./.7480.90   22920 28971920   /.3890920.439.

.98.920.25147.2920 8971920 8975920 89794920  #09:73890&392089.4./.90 472.

920./.47/3944.0809938 !...90.7808..

:77039920.8.90./.25 #09:73890.9047920394.90/98971920  !.900307.&3 92089./.338909:.&392089.25        920     !!.7808.

250$:3 :  &%  # $:3 :    #$$ $:3 :  &%  47//00-438479:2 0.398 !!3/.250$:3 :   &%  $   0.250   %   %%!4408 0.250$:3 :  &%  #  0.4389.0784341!!9.%204389.98:55479890.75943 942 0.908900.39  4389.250$:3/.250$:3/.  :  &%   # 0.39 %*%  %*  08.7089.  :  &%  !!   %*$   %*# %*#  %*#  %*# %*# %*#$$ %*    #  0.250   %         ..250   %   # 0.

:/010 47034:.08  $07.4393:000.901:3.:9089 990 3.:7703910  1.:/08 $$  4:.4:70-5.0700./078 1449078 4700203989.943 %03.3/3./07 144907 47 203:10147./07300/894-0:5/.3.:/088..059490..078/03.07747 .90/ 4:.250 88:209.:/0 1:3.:/0 1:3.0944:7890 4:.93903843.3077474.4209424205.759./41 :5/.908.:/0 0307.33807990.:/089390.70/039.3/0077478 O O 3.34907!!10-0147090807.:943  .94:..0 :80903.//..343:5/.08.70.759.:78 903.9438./0710 .9438.9430307.0/0.494147 %820../07103.08.908.3/.0.08 03900.9438 0.:/0900.733 -:9908.943 92 -4/  553.9439. 5.90.7/0.:/0 :3.7598945 %080941:3..90.9-070:80/43 2:9505.:/00 $07.:/0 1:3.389.30.4:70-5.07$/03.4393:000.   !!3.4390393.94:./07 55 %43.89./07 55  0.7/0.850.3090203:10 3890.:/0 0.:943 706:70 0307.3/908..908. 0.733 -:9908.07..3825.70.943  %0941:3.:/0 47706:70 1:3.305.70:80/94.9090 3.1.3/....08   !!3.43903941430!!10394.89..10/10.9.0.

 5$420909 .

5  .

-4/ .

0/203: 55 9.89.984:/-0:80/43.92 .0..3/.08 .5..250 88:200.7/203:10 .

.701.

/01.:9 55420.

701.. .

8.9:947.8 55%:947.

. .701.

7010703.08.08 55#010703.

701. ..

0.2508 55.2508.

 ..701.

.-4:9 55-4:9&8.

 .701..

.9&8.9 55439..439..

 5..88019203: 553..:/0 203: 55  .:/098203:10 070849..083900-89084:/3..3-0/430 92 -4/  /.

0 .  0./.4209424205.

 5$420909 .

5  .

-4/ .

0..-4.701.0 3.99084:7.0.88019203: .-74807 944098 92 -4/  /..4/041905.92 14:44.

/01.:9 55420.

 .701..

9:947.8 55%:947.8.

701.. .

7010703.08.08 55#010703.

 .701..

0.2508.2508 55.

.701. .

-4:9 55-4:9&8..

 .701..

..439.9&8..9 55439.

 ..

/.4209424205.  0.0.

 5$420909 .

5  .

-4/ .

92   .

2503.908.943 %0706:70 1:3.:943  %0706:70 0307.07747 .4393:000.943.3/908.733 -:9908.99.9..9438/039..40447/   .:78 903.1.3/08077478/1107039  1.0599.!!706:70 :3.:/0 7430 55  0.908.943 92 -4/  55 3.:/0 1:3.7598945  7747.:/0 :3.:/0 0.9430307..759.3077474.

-4/ .

9 5550.92 77472088.759 00.902039800.1047/70.9900..:943  7747.7  34200-8909089 554330  0447/ 49.250706:70 :3.2 48:.943 3.:/0*5.7333.733/4083498945908.:80.:/0 1:3.943 4 09 87:3908.:/0 7430 55 1:3.489.:843 3.0/45033 7430 55 1473.200.943 3.943  92 -4/  55 706:70 7430 55  .:90/%88-0..09.0/9445038970.0 .94734200-8909089 554330  .:/0( 1.:/0( .7333.250990706:70 1:3.

0.40447/   .

-4/ .

902039834900.759884:/349             .2 48:.9 5550.9.9.307747  -0.489.:/0 .1047/70..07747706:70 1:3.943 706:70( 1.:/0*5.943 706:70( .1907.7  34200-8909089 554330 %00.0/9445038970..94734200-8909089 554330  .0/45033706:70/ 7430 55  3.733706:70 7430 55 1:3./413.:80908.:808.75900.1907901.07747  9870.42203/0/94:8090706:70 1:3.0 .92 77472088.:90/ -0.:943894550/.9433890.4393:0.

943.20907850.43/ 5.  !!0.420 99 7    .7.24/0901084:/-045030/ 92 -4/  55 1014503 0.3/3  %014503 1:3.1083.2090741981:3.0 %014503 1:3.439.3/9080.38903.7.9438:80/9445031083!!  5033.2041901094-045030/.9438:80/9445031083!!  %017895.

-4/ .

/.92 %0102./43 $9.990-0333419010 #0.798.75943 #0.-045030/34304190144324/08 4/08 7 7   08.

790 $9.908.7890.990-0333419010 79043  5038.798./.3/.301019/4083 9 089 #0.4390398411047.70.0.

908.3/7908949003/41901047.301019 /4083 9089 5503/  5038.4390398411047.790  5038.70.908./.70.0.7890.301019/4083 9 089 #0.3/.

70.307747110./0898 #0.3010 #09:738$.5503/ !70807.908.439039-793949003/419010 79043 70./.0810.3/.

    .908. .70.3010 #09:738$.790 70.3/./0898   .307747110.

-094450310    .10/10 92 -4/  55 1014503 0.420 99 7 4709 &3.2500307.9438:3.019014503 1:3.-094450390850.80  .49019014503 1:3.250 %014430.10/10 9709:738  1.-094450390850.9438:3.908.2088.

-4/ .

0 %01.92   483.480 1:3.9438:80/94.480.3450310 55 1014503 9089 99 7   .

.

3/24/0 1 1041 10  0.480 10     0.9438:801:1474453974:/.8-00370.334970.43/4110 . .:90/  1.819003/ 41 10   .943..3/ 41 10 %01041 1:3./174210845030/3 ..0/   %01041 1:3.0.8420.41:3343039  4904:.4/094-000.9.

/8.830301742.9439010543907.250-0470. #0./.1030-30 :399003/4110870..9438:80/9470.94981:3.-094450310  .420 99 7 4709 &3..824.0/ 55 1014503 0.0/949030930  ..030-30 %01098 1:3.250 %00./3.10  4901907.

.

.30419010:399003/870. :95:9.0/ 0 1041 10   0.41098 10 -7.

907-.9438:80/9470..480 10     .0/ 55 1014503 0. 10  < 1...420 99 7 4709 &3.480 10     #0..907-.0...250 %00./. < 1.94981:3.907  ... 1:3..10  4901907.7.907 %0109.7.943901054390724..-094450310  0 1041 10   0.830.10.089490309.907 :399003/4110870.7.9071742.7.7..250-0470.7..4109../3./8.

110.9438  !!0889023974/:.0    !!088902:3..-083..470 %070834389.-0 !!**$$% !!** /01..039147!!94803/ ..7.//7088  !!** 1742  .28 .90901088902   389.9438 .088..75943 4814503 9501:3..039 01.:9*84....0!! .47419010889021:3.!!088902#010703.90/-809938355 3  088902.8847/ 4:702.9078 .794190!!.0!!   0130890:807.1:7010703.:99204:9 380.30 03/3..94389447 9&#8 .-083.23090 !!** /.:94*/090..34324:8%!5...04190!!10889021:3.894:7!!088902#010703.431:7.943 %0-0.43/8 147 !!** 84.943 %010889021:3..0!!   ..705...-083.9438.9*30*03/38   0380994 !!0.0 !!   0130890..35:.09-.9438   #:3920431:7./-1098 .3/2..70..:9  & 08.3/10 9480019 8:83&3 $ 4847.80/8970.09*9204:9   $09890/01.943 %010889021:3.9438.-083.20 .4*:7*14503 :807*.44:94.30.943300/0/94:809080 1:3.943459438 ..9.0 47.94388.

     &3.

943&35.13.5.914728 90147.8 .3/48425.9-9 03850.7/8.

8/70.8 .947  40.7/8.7.947805. 8:80/.914728 -49147.07 433/485.

4254303941.3/-..5.9438 !!3/...43 08.9473.5.3-0:80/   !!088902:3.943  :3./70..8041..947 .908900.*85.3450310 %089814703/ 41 1043.480 1041 11:8       .947 #09:73890949.30890104307 0..78901089.3450310 :808-:11070/4:95:994.7089.9 #09:73890170085...8.8  .0..9:8.0 /8170085.75 ./70.803.943 -..0 .45   /0090  /73.0  4808.4254303941.20 .789.0 /8*949..98:554798901:3.0784341!!9.10 $00:33 47:3809  #09:73890/70.3450310 !!                   .308901024/0 .75943 #09:73890103.9. .20.20.041.308901074:5 .20  /8*1700*85.0 1..841/8*1700*85.9 .24/ .0 4508.

94392041...10/5.9470898 #0.10394.3450310 #09:738.9.10 #09:73890.109.87024.897394..3/7908994.301742.9071742. 0.1047/70.808..389.920 10..3450310 .           132.77.8.3/790890708:99490 4:95:9-:1107 472.3450310 :39  .8924/1..4390398 10*5:9*.10 #09:7389034/03:2-0741.89.8973 7908.920 1074:5 1034/0 102920 104307 1050728 1080 10950 14.3450310     109.20478973.89.8090747349.  #09:738.9.0/ 1742.30 9%.0.10 #09:73890.301742.98.3/!!9.3147$'10/8 #09:738.   .1047&# #0./8.103.3092041.850.8$'.10 #09:738901080 #09:7389010950 4.34503 10 #0.10 #09:7389050728843841.08892041.4390398   10.8897:  15:9.3.99073 5038. 1098 10988    10                   10*0898  10*09*.10 #09:7389074:541.7./81742.3450310 !.10 #09:73890:807 4307 41..10 .30.10 #09:73890.847700. 14503   15..8.08./8.7808.10394.

850..9 $0083.10/039 790894.-4:9.31 1800 189.3.943./81742.47/394./ 18..3450310 #09:73831472.:770395489433.9 190  .208..3450310 #09:73890.41103.3450310.908..3450310 %7:3.3450310 #09:738.15:98 170.8411790  #0.345031094.10/1472.850.77.3450310 !.780835:91742.

7/3 #09:73831472.304.:9.943.8:54.70:.943               197:3.-0 3     3314 89./0/1094.08..3 0./.80907../70.80907..947 4..710 0.108.10.9.%%!! $% 0.90 1790 4-    8*/7               8*00.-0 8*790.-4:9.0*:54.908.947082.:9.10800.3 70.80907.-4:9.8418*79.99073 0.-0 0.80907.947 0./0/*10 8*79.80907./0/*10  .10870.3./70./0/.908.850.9 2/7    24.943.7/3 #09:73831472.108.104782-4..-0  70.-0 ./70./.-0 8*10 8*3    8*70.80907.80907.-0 0.108790.108.3:54.-0  8*:54.10/ 5.

94392041.947 #03/8.3 70.08.5..55045030/-54503  5038.710 70.94310 #09:73831472./10 70..10 .208.70941.398 !!3/.0784341!!9.3/7908994904:95:9-:1107 #09:738909.5.9   823  90253.1047/70.7808.10543907 #024.908900.105. :2./3 70.9 4808.3450310 #09:73831472.8 :33        !!0889024389..20 #03.39 08.088.-4:9.710 $098.908.-4:9.-84:905.98:55479890.947 $09890-:11078041..10.4389.82-4..2 92510 94:.431:7.9314 5./8.9 703.30810507288438147108 00908.93.30259/70.550 #0.3 #09:73890.943.480 54503 70.39  4389.908.3/24/1.:36:0902547.10                            809*10*-:1107 89.75943 !! .943.7089.20 703/ 72/7  !.780*3*10 5.:36:0902547.10 70.908.82-4.

 *#  * #  *#  * $ #%  *   * $! !% *# !% *$ !% *%$  *&$*&*!% *!! * #**$ *$!*!%*$                                      .

/  9!! 985488-094:54.9901443%1472147:54.90./ 0472 %4.4:807894:54./*10 552094/5489 03.1472.07  70./3108 92 -4/  1472./1089490807.9502:95./1081742.3-0.  !!0&54.79...07:801:  44.943:54.3&54.

-01471003.20. .9.1472 /.

-0 35:9950103..2010/10.

 -7.

 35:99508:-293..208:-29.:0$:-29.

 .

1472  .

-4/ .

0 O O %003.0901443.-4:990%1472.-4.439039 95094:80038:-2993 901472 2:95.997-:90419014729.79.850.92 49..108.950.

-74807 9070-0.1089./*10 5510./$.850.4/0147:54.7/.47747 *$10(07747( -7.997-:90419035:99./1088.439./8   70.-80./0/ %095010.90%0&54.0880/.-7480 -:9943309949035:9 10/ 49043:807894:54.9.759 %0:54. 090.10 55 1 *$10(07747(   0.1472706:708-3.3890.10 94-0:54.00/3.99035:984:/-0574. 10 470.8:80/03.1472 /.9./3.:7978  35072997:890/:807894507147210 :54.250 03.8.439039841 .

 < 080 .

4&54./ *$10(3. 0.20( -7.

4%50 *$10(950( -7. 0.

4$0  *$10(80(. 0.

   --7.

//842070897..943843&54.//70897.209078901472 835:93.20( 903.3-009073.4$9470/3 *$10(925*3.0.039.4/0708:9317429010:54.8438 4:84:/..!!*$.20( <  :83904-.:7970.943843./ 147 50108 .07  %017895.77../ %0:8072.43/3/0.43:54.204707747 098 O O O O O *$10(3.425:9079490702490 807.3:54.40/94:54../0/10 *$10(925*3.41:54.204190902547.4:.9438949010:54./1081742./3108 4780./0/10 *$10(80( 90803-9084190:54.078250.9 90:8078./ %88./ 3988. 0./0/10 *$10(950( 909504190:54.3/9080.20 950  80 925*3.3/9010802:89-0:3/07 - 55 1 *$10(950(2./   #0897.20( 903.4541901089470/4390807.7.7.7590.07 *$10(07747( 9007747.20.204190:54.

1   *$10(950(2.0.

50   *$10(950(2.0.

550   *$10(80(   1 *$10(07747(   0.47747 *$10(07747( -7.

/ *$10(3.4&54. < 080  0.20( -7.

 0.4%50 *$10(950( -7.

 0.4$0  *$10(80(.

   --7.

 0.20( < < 080  0./10 < .4$9470/3 *$10(925*3..43.

07  %0902547.-4.454190:54./0/108390!!902514/074390 807.90..450/108/8.390&54.2508.0.7./11070394.0.550.70./0/0 %00. 490479470../0/100300/94 .4305108909502:89-0550 14770492:89-050   $.75903/8 %48947090:54.7.902547.7803908.45994.943 55 1 *$10(950(2.

0.1   *$10(950(2.

0.50   *$10(950(2.

550   *$10(80(   1 *$10(07747(   0.4#09:734/0 *$10(07747( -7.

 < 080  0.20( -7.4&54./ *$10(3.

 0.4%50 *$10(950( -7.

 0.4$0  *$10(80(.

   --7.

4%02510 *$10(925*3. 0.20( -7.

  1 10*0898 :54./.

/.70./0898  < 080  24.4*$10(3./0/*10 *$10(925*3.20(  :54.20(   0.0*:54.20( . *$10(3.

 *$10(3.4$9470/3 :54.20(  0./.

0/:54. *$10(3.08901094.70.759.20( < < < 080  0..2508../ .3014/07.819010.-4.0./10 <  %08.0./0898 19/408349 9.450890109490850..43.10/14/07  490%80.

3./  .:04190.:08   49470..250 4:.3/ .440 .4/0/03803/390.43/8  55 .:807 .20/:807..9 /42.440 :807 0!47907 920   92    490%0.440944  9!! 4:.550.90.440 1:3.4/0/0370.440 3.0/ 94570.440841903:80/94/0391.3:83 80.109.0. 92.440 %0809.0702-0/84390:807 8 .8480990057...440.3/70970.9.3-49.90.7 #90929.440841903:80/94/0391..34907.5..3  .250-04 0.920908.0.4403.20 .425:907 ..:00!47907949  0.250 3900.039&#03.440  490%0809.990807.9438:80/94809.20.90.44084:/0570.990.82.4/3 :808097.../0.70.3/. 809.440 1:3.-00.  !!4408  .9439204190.425:907706:0898.&#03.8079.:0 0570 5.98.4408.:942.19.-74807 9803/90.4408.:807  .19074304:7 55 809.  $39.88390.4403.70.9432:89.09..440 3890.440 .:942...84850.9.

250.  23 4:78  /.8   494#0970.440'.:04190.3//85..250-04 070970.0570920      809.090057.440.0.:0 %0!!* .-08:80/9470970.943920880994.090.0.20/:807.4403.7..440 :807 0!47907 0570    92  3900.-4..0 55 ..943.2439  80.:0   3900.5.

.

!739.440 0.4* :807(  ..

.

40..9439413/4:91.4408 5739*7 *    39014430..94.420 * :807( -7.8-003809 92 -4/  55 1 8809 * :807(  0.440..0.2500:80908809 1:3.

420:089-7. 080 0.40.

   .

-4/ .

92   .

.440 03/0093.4940090.89  00900.88:709.250 55 .990057.943/.9083905.4404:84:/.

.

91.84390$:-29-:9943 92 -4/  1472..9430.3/:80735:9.943/0.9/43498:55479.70/08.4408 4:.9.55.74807408 %$:554794408 14:7..80990057.55.943  302094/8945.974:14728 14728.4 809..203.3490734:7.880890:80735:9940.94317424305.  %01472-045.89-7480789.420 552094/5489 .8831472.420 550390:807...2035:99509093.440 :807  920      .7-0/0.094.90944304:7.8890 /.943/.094:804907 2094/8945.7073989:947.20.

 035:99509093.0.20.

 35:99508:-29.

 .

1472  .

-4/ .

420 5510098 92 -4/  0.420550.20( -7.92 #0970.4*! $%3..090.:083900.

 4:.70550.4*! $%.0(0.784/   .

-4/ .

.

92                        .

    .

Sign up to vote on this title
UsefulNot useful