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.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Javascript Introduction Norman White Material is from w3schools.com Go there to run examples interactively.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
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.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
ALBERT WAVERING BOBBY SENG. Week Whatever: PHP  Announcements/questions/complaints.
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
PHP / MySQL. What is PHP? PHP is an acronym for "PHP Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Nael Alian Introduction to PHP
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
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.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
PHP Programming with MySQL Slide 4-1 CHAPTER 4 Functions and Control Structures.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
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.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
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.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Introduction to PHP.
הרצאה 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.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
 A PHP script can be placed anywhere in the document.  A PHP script starts with  The default file extension for PHP files is ".php".  A PHP file normally.
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.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
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,
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
PHP-Basic By- Tanvi Raval. Pre-requisites Before you continue you should have a basic understanding of the following: 1. HTML 2. JavaScript.
11 – Introduction to PHP(1) Informatics Department Parahyangan Catholic University.
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.
By bscshelp.com 1.  It is a group assignment.  Complete Website design Using Html and Css.  Due date: 10 th December, 2014 (Hard Deadline) 2.
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.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
PHP 5 Syntax.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to Web programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP Rasmus Lerdorf.
PHP Introduction.
Chapter 19 JavaScript.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
PHP an introduction.
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
Contact PSK Technologies Pvt. Ltd IT Company Address - Plot No-780, Near Durga Temple, Katol Road Chaoni, Nagpur-13.
Presentation transcript:

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 the server PHP costs nothing, it is free to download and use

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, 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 restrict users to access some pages on your website PHP can encrypt data With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

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

Install PHP What Do I Need? To start using PHP, you can: Find a web host with PHP and MySQL support Install a web server on your own PC, and then install PHP and MySQL

Go to Download XAMPP Windows installer

PHP 5 Syntax My first PHP page

Comments in PHP

PHP Case Sensitivity In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are case-insensitive. In the example below, all three echo statements below are legal (and equal): "; echo "Hello World! "; EcHo "Hello World! "; ?>

However; in PHP, all variables are case-sensitive. "; echo "My house is ". $COLOR. " "; echo "My boat is ". $coLOR. " "; ?>

PHP 5 Variables Variables are "containers" for storing information Rules for PHP variables: 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 ($y and $Y are two different variables)

"; echo $x; echo " "; echo $y; ?>

PHP Variables Scope In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: local global static

Local and Global Scope A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function. A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function.

Test variables inside the function: "; echo "Variable x is: $x"; echo " "; echo "Variable y is: $y"; } myTest(); echo " Test variables outside the function: "; echo "Variable x is: $x"; echo " "; echo "Variable y is: $y"; ?>

PHP The global Keyword

PHP The static Keyword Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job.

"; myTest(); echo " "; myTest(); echo " "; myTest(); echo " "; myTest(); ?>

PHP 5 echo and print Statements In PHP there is two basic ways to get output: echo and print. There are some difference between echo and print: echo - can output one or more strings print - can only output one string, and returns always 1

The PHP echo Statement Display Strings PHP is fun! "; echo "Hello world! "; echo "I'm about to learn PHP! "; echo "This", " string", " was", " made", " with multiple parameters."; ?>

Display Variables "; echo "Study PHP at $txt2"; echo " "; echo "My car is a {$cars[0]}"; ?>

The PHP print Statement Display Strings PHP is fun! "; print "Hello world! "; print "I'm about to learn PHP!"; ?>

Display Variables "; print "Study PHP at $txt2"; print " "; print "My car is a {$cars[0]}"; ?>

PHP Data Types String, Integer, Floating point numbers, Boolean, Array, Object, NULL.

PHP Strings "; $x = 'Hello world!'; echo $x; ?>

PHP Integers An integer is a number without decimals. Rules for integers: An integer must have at least one digit (0-9) An integer cannot contain comma or blanks An integer must not have a decimal point An integer can be either positive or negative Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0)

"; $x = -345; // negative number var_dump($x); echo " "; $x = 0x8C; // hexadecimal number var_dump($x); echo " "; $x = 047; // octal number var_dump($x); ?>

PHP Floating Point Numbers "; $x = 2.4e3; var_dump($x); echo " "; $x = 8E-5; var_dump($x); ?>

PHP Booleans Booleans can be either TRUE or FALSE. var x=true; var y=false; Booleans are often used in conditional testing.

PHP Arrays

PHP Objects An object is a data type which stores data and information on how to process that data. In PHP, an object must be explicitly declared. First we must declare a class of object. For this, we use the class keyword. A class is a structure that can contain properties and methods. We then define the data type in the object class, and then we use the data type in instances of that class:

color = $color; } function what_color() { return $this->color; } } function print_vars($obj) { foreach (get_object_vars($obj) as $prop => $val) { echo "\t$prop = $val\n"; } } // instantiate one object $herbie = new Car("white"); // show herbie properties echo "\herbie: Properties\n"; print_vars($herbie); ?>

PHP NULL Value

PHP String Functions The PHP strlen() function

The PHP strpos() function

For a complete reference of all string functions go to ng.asp ng.asp

PHP Constants A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.

Set a PHP Constant To set a constant, use the define() function - it takes three parameters: The first parameter defines the name of the constant, the second parameter defines the value of the constant, and the optional third parameter specifies whether the constant name should be case- insensitive. Default is false.

"; // will not output the value of the constant echo greeting; ?>

"; // will also output the value of the constant echo greeting; ?>

PHP 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 Arithmetic Operators

AssignmentSame as...Description x = y The left operand gets set to the value of the expression on the right x += yx = x + yAddition x -= yx = x - ySubtraction x *= yx = x * yMultiplication x /= yx = x / yDivision x %= yx = x % yModulus PHP Assignment Operators The PHP assignment operators is used to write a value to a variable. The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.

OperatorNameExampleResult.Concatenation$txt1 = "Hello" $txt2 = $txt1. " world!" Now $txt2 contains "Hello world!".=Concatenation assignment $txt1 = "Hello" $txt1.= " world!" Now $txt1 contains "Hello world!" PHP String Operators The example below shows the results of using the string operators:

OperatorNameDescription ++$xPre- increment Increments $x by one, then returns $x $x++Post- increment Returns $x, then increments $x by one --$xPre- decrement Decrements $x by one, then returns $x $x--Post- decrement Returns $x, then decrements $x by one PHP Increment / Decrement Operators

OperatorNameExampleResult ==Equal$x == $yTrue if $x is equal to $y ===Identical$x === $yTrue if $x is equal to $y, and they are of the same type !=Not equal$x != $yTrue if $x is not equal to $y <>Not equal$x <> $yTrue if $x is not equal to $y !==Not identical$x !== $yTrue if $x is not equal to $y, or they are not of the same type >Greater than$x > $yTrue if $x is greater than $y <Less than$x < $yTrue if $x is less than $y >=Greater than or equal to $x >= $yTrue if $x is greater than or equal to $y <=Less than or equal to$x <= $yTrue if $x is less than or equal to $y PHP Comparison Operators The PHP comparison operators are used to compare two values (number or string):

"; var_dump($x === $y); // returns false because types are not equal echo " "; var_dump($x != $y); // returns false because values are equal echo " "; var_dump($x !== $y); // returns true because types are not equal echo " "; $a=50; $b=90; var_dump($a > $b); echo " "; var_dump($a

OperatorNameExampleResult andAnd$x and $yTrue if both $x and $y are true orOr$x or $yTrue if either $x or $y is true xorXor$x xor $yTrue if either $x or $y is true, but not both &&And$x && $yTrue if both $x and $y are true ||Or$x || $yTrue if either $x or $y is true !Not!$xTrue if $x is not true PHP Logical Operators

OperatorNameExampleResult +Union$x + $yUnion of $x and $y (but duplicate keys are not overwritten) ==Equality$x == $yTrue if $x and $y have the same key/value pairs ===Identity$x === $yTrue if $x and $y have the same key/value pairs in the same order and of the same types !=Inequality$x != $yTrue if $x is not equal to $y <>Inequality$x <> $yTrue if $x is not equal to $y !==Non-identity$x !== $yTrue if $x is not identical to $y PHP Array Operators The PHP array operators are used to compare arrays:

"red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); $z = $x + $y; // union of $x and $y var_dump($z); echo " "; var_dump($x == $y); echo " "; var_dump($x === $y); echo " "; var_dump($x != $y); echo " "; var_dump($x <> $y); echo " "; var_dump($x !== $y); ?>

array(4) { ["a"]=> string(3) "red" ["b"]=> string(5) "green" ["c"]=> string(4) "blue" ["d"]=> string(6) "yellow" } bool(false) bool(false) bool(true) bool(true) bool(true)

PHP Conditional Statements PHP - The if Statement The if statement is used to execute some code only if a specified condition is true. Syntax if (condition) { code to be executed if condition is true; }

PHP - The if...else Statement Use the if....else statement to execute some code if a condition is true and another code if the condition is false. Syntax 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 Use the if....elseif...else statement to select one of several blocks of code to be executed. Syntax if (condition) { code to be executed if condition is true; } elseif (condition) { code to be executed if condition is true; } else { code to be executed if condition is false; }

The PHP switch Statement Use the switch statement to select one of many blocks of code to be executed. Syntax switch (n) { case label1: code to be executed if n=label1; break; case label2: code to be executed if n=label2; break; case label3: code to be executed if n=label3; break;... default: code to be executed if n is different from all labels; }

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

"; $x++; } ?>

The PHP do...while Loop "; $x++; } while ($x

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

"; } ?>

The PHP foreach Loop The foreach loop works only on arrays, and is used to loop through each key/value pair in an array. Syntax foreach ($array as $value) { code to be executed; } For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.

"; } ?>

PHP Functions PHP User Defined Functions Syntax function functionName() { code to be executed; } A function name can start with a letter or underscore (not a number)

PHP Function Arguments "; } familyName("Jani"); familyName("Hege"); familyName("Stale"); familyName("Kai Jim"); familyName("Borge"); ?>

"; } familyName("Hege","1975"); familyName("Ståle","1978"); familyName("Kai Jim","1983"); ?>

PHP Default Argument Value "; } setHeight(350); setHeight(); setHeight(135); setHeight(80); ?>

PHP Functions - Returning values "; echo " = ". sum(7,13). " "; echo "2 + 4 = ". sum(2,4); ?>