PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Php. What is PHP? PHP is an acronym for "PHP Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on.
PHPPHP What is PHP? Hypertext Pre-processor (PHPs) is a server- side scripting language In early versions, PHP stand for Personal Home Page. server-side.
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
Nael Alian Introduction to PHP
Variables, Operators and Data Types. By Shyam Gurram.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
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.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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 Constructs Advance Database Management Systems Lab no.3.
Introduction to PHP.
Outline if...else...elseif Statements Switch Loops Functions Arrays Forms.
PHP. PHP User Defined Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used.
הרצאה 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.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
CHAPTER 7 Introduction to PHP5 Part II อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
PHP Variables.  Variables are "containers" for storing information. How to Declare PHP Variables  In PHP, a variable starts with the $ sign, followed.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
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.
 An array stores multiple values in one single variable.  Example: Output: I like Honda Civic, BMW and Toyota.
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,
11 – Introduction to PHP(1) Informatics Department Parahyangan Catholic University.
CGS 3066: Web Programming and Design Spring 2016 PHP.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
 The real power of PHP comes from its functions; it has more than 1000 built-in functions.  PHP User Defined Functions  Besides the built-in PHP functions,
PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.
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.
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)
CGS 3066: Web Programming and Design Spring 2017
CHAPTER 5 SERVER SIDE SCRIPTING
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to Web programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
PHP Introduction.
Introduction to Web programming
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
PHP an introduction.
PHP Array.
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
Web Application Development Using PHP
JavaScript CS 4640 Programming Languages for Web Applications
Contact PSK Technologies Pvt. Ltd IT Company Address - Plot No-780, Near Durga Temple, Katol Road Chaoni, Nagpur-13.
Presentation transcript:

PHP Tutorial

What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.

What is a PHP File PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code are executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php"

What Can PHP Do PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in your database PHP can be used to control user-access PHP can encrypt data

Why PHP PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP supports a wide range of databases PHP is free. Download it from the official PHP resource: PHP is easy to learn and runs efficiently on the server side

PHP 5 Syntax A PHP script is executed on the server, and the plain HTML result is sent back to the browser A PHP script can be placed anywhere in the document. A PHP script starts with : –

PHP 5 Variables Variables are "containers" for storing information In PHP, a variable starts with the $ sign, followed by the name of the variable –$text = “This is a text”

PHP Variables A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). A variable starts with the $ sign, followed by the name of the variable A variable name must start with a letter or the underscore character A variable name cannot start with a number A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables)

The PHP echo Statement The echo statement can be used with or without parentheses: echo or echo() The following example shows how to output text with the echo command (notice that the text can contain HTML markup): – PHP is Fun! "; echo "Hello world! "; echo "I'm about to learn PHP! "; ?>

PHP 5 Strings A string is a sequence of characters, like "Hello world!" The PHP strlen() function returns the length of a string – For a complete reference of all string functions, go to: –

PHP Operators Operators are used to perform operations on variables and values. PHP divides the operators in the following groups: –Arithmetic operators –Assignment operators –Comparison operators –Increment/Decrement operators –Logical operators –String operators –Array operators

PHP Arithmetic Operators The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

PHP Arithmetic Operators OperatorNameExampleResult +Addition$x+ $ySum of $x and $y -Subtraction$x - $yDifference of $x and $y *Multiplication$x* $yProduct of $x and $y /Division$x / $yQuotient of $x and $y %Modulus$x % $yRemainder of $x divided by $y

PHP Assignment Operators The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the expression on the right

PHP Comparison Operators The PHP comparison operators are used to compare two values (number or string):

PHP Comparison Operators OperatorNameExampleResult ==Equal$x == $yReturns true if $x is equal to $y !=Not Equal $x != $yReturns true if $x is not equal to $y >=Greater or equal to $x >= $yReturns true if $x is greater than or equal to $y

PHP Conditional Statements In PHP we have the following conditional statements: –if statement - executes some code if one condition is true –if...else statement - executes some code if a condition is true and another code if that condition is false –if...elseif....else statement - executes different codes for more than two conditions –switch statement - selects one of many blocks of code to be executed

PHP - The if Statement The if statement executes some code if one condition is true –if (condition) { code to be executed if condition is true; }

PHP - The if...else Statement The if....else statement executes some code if a condition is true and another code if that condition is false. –if (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }

PHP - The if...elseif....else Statement The if....elseif...else statement executes different codes for more than two conditions. –if (condition) { code to be executed if this condition is true; } elseif (condition) { code to be executed if this condition is true; } else { code to be executed if all conditions are false; }

PHP 5 Loops PHP loops execute a block of code while the specified condition is true Often when you write code, you want the same block of code to run over and over again in a row –Instead of adding several almost equal code- lines in a script, we can use loops to perform a task like this

PHP while Loop The while loop executes a block of code as long as the specified condition is true. –while (condition is true) { code to be executed; }

PHP for Loops The for loop is used when you know in advance how many times the script should run. –for (init counter; test counter; increment counter) { code to be executed; }

PHP 5 Functions The real power of PHP comes from its functions; it has more than 1000 built-in functions You can find all these function by going to: –

PHP User Defined Functions Besides the built-in PHP functions, we can create our own functions A function is a block of statements that can be used repeatedly in a program A function will not execute immediately when a page loads A function will be executed by a call to the function.

Create a User Defined Function in PHP A user defined function declaration starts with the word "function": –function functionName() { code to be executed; }

PHP Function Arguments Information can be passed to functions through arguments – An argument is just like a variable. Arguments are specified after the function name, inside the parentheses –You can add as many arguments as you want, just separate them with a comma.

Example (Function with 1 argument) – "; } familyName("Jani"); familyName("Hege"); familyName("Stale"); familyName("Kai Jim"); familyName("Borge"); ?>

Function with two arguments – "; } familyName("Hege", "1975"); familyName("Stale", "1978"); familyName("Kai Jim", "1983"); ?>

PHP Default Argument Value The following example shows how to use a default parameter – "; } setHeight(350); setHeight(); // will use the default value of 50 setHeight(135); setHeight(80); ?>

PHP Functions - Returning values To let a function return a value, use the return statement: – "; echo " = ". sum(7, 13). " "; echo "2 + 4 = ". sum(2, 4); ?>

PHP 5 Arrays An array stores multiple values in one single variable: –

What is an Array An array is a special variable, which can hold more than one value at a time An array can hold many values under a single name, and you can access the values by referring to an index number

Create an Array in PHP In PHP, the array() function is used to create an array: –array();

PHP Array types In PHP, there are three types of arrays: –Indexed arrays - Arrays with a numeric index –Associative arrays - Arrays with named keys –Multidimensional arrays - Arrays containing one or more arrays

PHP Indexed Arrays There are two ways to create indexed arrays: –The index can be assigned automatically (index always starts at 0), like this: $cars = array("Volvo", "BMW", "Toyota"); –or the index can be assigned manually: $cars[0] = "Volvo"; $cars[1] = "BMW"; $cars[2] = "Toyota";

Get The Length of an Array The count() function is used to return the length (the number of elements) of an array: –

Loop Through an Indexed Array To loop through and print all the values of an indexed array, you could use a for loop, like this: – "; } ?>

PHP Associative Arrays Associative arrays are arrays that use named keys that you assign to them. There are two ways to create an associative array: –$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); –$age['Peter'] = "35"; $age['Ben'] = "37"; $age['Joe'] = "43";

PHP Associative Arrays The named keys can then be used in a script: – "35", "Ben"=>"37", "Joe"=>"43"); echo "Peter is ". $age['Peter']. " years old."; ?>

Loop Through an Associative Array To loop through and print all the values of an associative array, you could use a foreach loop, like this: – "35", "Ben"=>"37", "Joe"=>"43"); foreach($age as $x => $x_value) { echo "Key=". $x. ", Value=". $x_value; echo " "; } ?>