PHP. 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.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

More on PHP Coding Lab no. 6 Advance Database Management System.
SWU, Computer systems and technologies. The Objective of This Lecture To give you a very high-level overview of some of the tools for Web Programming.
XAMPP: Cross – Apache, MySQL, Php, Perl + FileZilla, Tomcat NetBeans: IDE PHP Installation.
PHP & MySQL Mahak Arora Vivek Bangera. Outline How PHP works Basic scripting in PHP Forms in PHP(GET & POST Variables) SQL basics PHP and MySQL connection.
WHAT IS PHP PHP is an HTML-embedded scripting language primarily used for dynamic Web applications.
PHP By Dr. Syed Noman Hasany. PHP PHP was originally created by Rasmus Lerdorf in PHP stands for PHP: Hypertext Preprocessor (a recursive acronym).
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
04/09/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
PHP Tutorial By RAY BALIKI && ROY GHORAYEB. DEFINITION PHP is a powerful server-side scripting language for creating dynamic and interactive websites.
INTRODUCTION TO PHP Basic concept of PHP and Much More Prepared By: Farhan Nisar(7 th Semester) University of Peshawar.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
COMP Week 5 Dr. Chunbo Chu. Agenda 1. Brief History of PHP 2. Basics 3. Advanced.
Mandakini Ayushi Infotech Mandakini Kumari 22 nd July PHP Basic.
PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is a powerful.
Languages in WEB Presented by: Jenisha Kshatriya BCM SS09.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
Nael Alian Introduction to PHP
PHP - Introduction Week 5 Dr. Ken Cosh Introducing PHP 1.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Web Programming Language Week 5 Dr. Ken Cosh Introducing PHP 1.
PHP. 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.
Julian Springer Room 42 Joe Slovo.  W3 schools recommend that you have a basic understanding of HTML and of JavaScript before attempting to grasp PHP.
Introduction to PHP Advanced Database System Lab no.1.
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.
PHP Arrays By Justin Nelsen. What is an Array? - An array can store one or more values in a single variable name. -Each element in the array is assigned.
Introduction to PHP.
8 th Semester, Batch 2008 Department Of Computer Science SSUET.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Introduction PHP is a server-side scripting language.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
Company LOGO In the Name of Allah,The Most Gracious, The Most Merciful King Khalid University College of Computer and Information System Web pages Development.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
PHP File Handling. Opening a file Fopen(filename,mode) Closing a file Fclose(filename)
A pache M ySQL P hp Robert Mudge Reference:
Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do this.
PHP using MySQL Database for Web Development (part II)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
8th Semester, Batch 2008 Department of Computer Science SSUET.
PHP Introduction.
Basic PHP Lecture by Nutthapat Keawrattanapat
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Basics (Cont...).
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Introduction to PHP.
PHP an introduction.
PHP-II.
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

PHP

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

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

Basic PHP Syntax PHP script always starts with.

Comments in PHP use // to make a one-line comment or /* and */ to make a comment block

PHP Variables Variables in PHP starts with a $ sign Variable names are case sensitive <?php $txt="Hello World!"; $x=16; $myCar="Volvo"; ?>

PHP Variable Scope The scope of a variable is the portion of the script in which the variable can be referenced. PHP has four different variable scopes: local global static parameter

Local Scope A variable declared within a PHP function is local and can only be accessed within that function The script above will not produce any output because the echo statement refers to the local scope variable $a, which has not been assigned a value within this scope

Global Scope Global variables can be accessed from any part of the script that is not inside a function Just use the global keyword The script above will output 15

The example above can be rewritten as this

Static Scope When a function is completed, all of its variables are normally deleted. However, sometimes you want a local variable to not be deleted. To do this, use the static keyword when you first declare the variable <?php $a = 5; $b = 10; static $rememberMe; function myTest() { global $a, $b; $b = $a + $b; } myTest(); echo $b; ?>

Parameters or arguments A parameter is a local variable whose value is passed to the function by the calling code ارجومنت الدوال function myTest($para1,$para2,...) { // function code }

String Variables in PHP Hello World

The Concatenation Operator The concatenation operator (.) is used to put two string values together Hello World! What a nice day!

The strlen() function The strlen() function is used to return the length of a string. 12

The strpos() function The strpos() function is used to search for a character/text within a string 6 first character position in the string is 0, and not 1

Arithmetic Operators

Assignment Operators

Incrementing/Decrementing Operators

Comparison Operators

Logical Operators

Array Operators

PHP If...Else Statements

"; echo "Have a nice weekend!"; echo "See you on Monday!"; } ?>

PHP Switch Statement

PHP Arrays An array stores multiple values in one single variable. $cars=array("Saab","Volvo","BMW","Toyota"); OR $cars[0]="Saab"; $cars[1]="Volvo"; $cars[2]="BMW"; $cars[3]="Toyota";

Saab and Volvo are Swedish cars.

Associative Arrays In this example we use an array to assign ages to the different persons: $ages = array("Peter"=>32, "Quagmire"=>30, "Joe"=>34); OR $ages['Peter'] = "32"; $ages['Quagmire'] = "30"; $ages['Joe'] = "34";

Peter is 32 years old.

Multidimensional Arrays In a multidimensional array, each element in the main array can also be an array. And each element in the sub-array can be an array, and so on. $families = array ( "Griffin"=>array ( "Peter", "Lois", "Megan" ), "Quagmire"=>array ( "Glenn" ), "Brown"=>array ( "Cleveland", "Loretta", "Junior" ) ); Array ( [Griffin] => Array ( [0] => Peter [1] => Lois [2] => Megan ) [Quagmire] => Array ( [0] => Glenn ) [Brown] => Array ( [0] => Cleveland [1] => Loretta [2] => Junior ) )

Add this code to the previous example echo "Is ". $families['Griffin'][2]. " a part of the Griffin family?"; The out will be Is Megan a part of the Griffin family?

PHP Looping - While Loops "; $i++; } ?> The number is 1 The number is 2 The number is 3 The number is 4 The number is 5

The do...while Statement "; } while ($i The number is 2 The number is 3 The number is 4 The number is 5 The number is 6

PHP Looping - For Loops "; } ?> The number is 1 The number is 2 The number is 3 The number is 4 The number is 5

The foreach Loop "; } ?> one two three

PHP Functions The real power of PHP comes from its functions. In PHP, there are more than 700 built-in functions My name is Kai Jim Refsnes

"; } echo "My name is "; writeName("Kai Jim"); echo "My sister's name is "; writeName("Hege"); echo "My brother's name is "; writeName("Stale"); ?> My name is Kai Jim Refsnes. My sister's name is Hege Refsnes. My brother's name is Stale Refsnes.

"; } echo "My name is "; writeName("Kai Jim","."); echo "My sister's name is "; writeName("Hege","!"); echo "My brother's name is "; writeName("Ståle","?"); ?> My name is Kai Jim Refsnes. My sister's name is Hege Refsnes! My brother's name is Ståle Refsnes?

PHP Functions - Return values = 17

PHP Forms and User Input Name: Age: "welcome.php" looks like this: Welcome ! You are years old. Welcome John! You are 28 years old.

The PHP $_GET and $_POST variables Name: Age: The "welcome.php" file can now use the $_GET variable to collect form data (the names of the form fields will automatically be the keys in the $_GET array): Welcome. You are years old! When the user clicks the "Submit" button, the URL sent to the server could look something like this: p?fname=Peter&age=37

When to use method="get"? When using method="get" in HTML forms, all variable names and values are displayed in the URL

PHP $_POST Function The predefined $_POST variable is used to collect values from a form sent with method="post“. Name: Age: When the user clicks the "Submit" button, the URL will look like this: The "welcome.php" file can now use the $_POST variable to collect form data (the names of the form fields will automatically be the keys in the $_POST array): Welcome ! You are years old. 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.

The PHP $_ REQUEST Variable The predefined $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. The $_REQUEST variable can be used to collect form data sent with both the GET and POST methods. Welcome ! You are years old.

PHP Date() Function "; echo date("Y.m.d"). " "; echo date("Y-m-d"); ?> 2009/05/ Tomorrow is 2009/05/12

PHP Include File Assume that you have a standard header file, called "header.php". To include the header file in a page, use the include() function: You can insert the content of one PHP file into another PHP file before the server executes it, with the include() or require() function. The two functions are identical in every way, except how they handle errors: include() generates a warning, but the script will continue execution require() generates a fatal error, and the script will stop

Example Assume that you have a standard header file, called "header.php". To include the header file in a page, use the include() function: Welcome to my home page! Some text.

Assume we have a standard menu file, called "menu.php", that should be used on all pages Home Tutorials References Examples About Us Contact Us All pages in the Web site should include this menu file. Here is how it can be done: Welcome to my home page. Some text.

If you look at the source code of the page above (in a browser), it will look like this: Home Tutorials References Examples About Us Contact Us Welcome to my home page! Some text.

File handling

The following example generates a message if the fopen() function is unable to open the specified file:

Closing a File The fclose() function is used to close an open file:

Check End-of-file The feof() function checks if the "end-of-file" (EOF) has been reached. The feof() function is useful for looping through data of unknown length. Note: You cannot read from files opened in w, a, and x mode! if (feof($file)) echo "End of file";

Reading a File Line by Line The example below reads a file line by line, until the end of file is reached: "; } fclose($file); ?>

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

Create an Upload-File Form To allow users to upload files from a form can be very useful. Look at the following HTML form for uploading files: Filename:

Create The Upload Script The "upload_file.php" file contains the code for uploading a file: 0) { echo "Error: ". $_FILES["file"]["error"]. " "; } else { echo "Upload: ". $_FILES["file"]["name"]. " "; echo "Type: ". $_FILES["file"]["type"]. " "; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb "; echo "Stored in: ". $_FILES["file"]["tmp_name"]; } ?>

$_FILES["file"]["name"] - the name of the uploaded file $_FILES["file"]["type"] - the type of the uploaded file $_FILES["file"]["size"] - the size in bytes of the uploaded file $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the server $_FILES["file"]["error"] - the error code resulting from the file upload

Restrictions on Upload The user may only upload.gif or.jpeg files and the file size must be under 20 kb: 0) { echo "Error: ". $_FILES["file"]["error"]. " "; } else { echo "Upload: ". $_FILES["file"]["name"]. " "; echo "Type: ". $_FILES["file"]["type"]. " "; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb "; echo "Stored in: ". $_FILES["file"]["tmp_name"]; } } else { echo "Invalid file"; } ?>

Saving the Uploaded File To store the uploaded file we need to copy it to a different location: 0) { echo "Return Code: ". $_FILES["file"]["error"]. " "; } else { echo "Upload: ". $_FILES["file"]["name"]. " "; echo "Type: ". $_FILES["file"]["type"]. " "; echo "Size: ". ($_FILES["file"]["size"] / 1024). " Kb "; echo "Temp file: ". $_FILES["file"]["tmp_name"]. " "; if (file_exists("upload/". $_FILES["file"]["name"])) { echo $_FILES["file"]["name"]. " already exists. "; } else { move_uploaded_file($_FILES["file"]["tm p_name"], "upload/". $_FILES["file"]["name"]); echo "Stored in: ". "upload/". $_FILES["file"]["name"]; }}} else { echo "Invalid file"; } ?>