PHP-Basic By- Tanvi Raval. Pre-requisites Before you continue you should have a basic understanding of the following: 1. HTML 2. JavaScript.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Introduction to PHP (Part-1) Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
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).
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
Chapter 4 – The Building Blocks Data Types Literals Variables Constants.
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.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
PHP. Why should we learn web programming? No need write socket programming. - You can forget TCP/IP & OSI layers. - Web server handles socket tasks for.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
Nael Alian Introduction to PHP
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
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.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
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.
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.
Introduction to Web Programming. Introduction to PHP What is PHP? What is a PHP File? What is MySQL? Why PHP? Where to Start?
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
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.
PHP Introduction PHP is a server-side scripting language.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Basic Scripting & Variables Yasar Hussain Malik - NISTE.
 Before you continue you should have a basic understanding of the following:  HTML  CSS  JavaScript.
PHP Syntax You cannot view the PHP source code by selecting "View source" in the browser - you will only see the output from the PHP file, which is plain.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
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,
CSE 154 LECTURE 14: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 1 Introduction to PHP Hypertext Preprocessor - PHP.
Unit – 3 Control structures. Condition Statements 1.If.…..else :- Has someone ever told you, "if you work hard, then you will succeed"? And what happens.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
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.
Introduction to PHP and MySQL (Creating Database-Driven Websites)
PHP stands for …….. “PHP Hypertext Pre-processor” and is a server-side scripting language like ASP. PHP scripts are executed on the server PHP supports.
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.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
A pache M ySQL P hp Robert Mudge Reference:
PHP using MySQL Database for Web Development (part II)
Introduction to Dynamic Web Programming
CHAPTER 5 SERVER SIDE SCRIPTING
Introduction to Web programming
PHP (PHP: Hypertext Preprocessor)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Server-Side Application and Data Management IT IS 3105 (Spring 2010)
PHP Introduction.
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
IntroductionToPHP Static vs. Dynamic websites
Intro to PHP.
Tutorial 6 PHP & MySQL Li Xu
Tutorial 10: Programming with javascript
Introduction to PHP.
PHP an introduction.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

PHP-Basic By- Tanvi Raval

Pre-requisites Before you continue you should have a basic understanding of the following: 1. HTML 2. JavaScript

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 is a database server MySQL is ideal for both small and large applications MySQL supports standard SQL MySQL compiles on a number of platforms MySQL is free to download and use

Why PHP? PHP is a powerful tool for making dynamic and interactive Web pages. PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. 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

PHP Installation What do you need? Most people would prefer to install a all-in-one solution: WampServer 2.0i for Windows platform Includes : - Apache MySQL PHP for Linux platform

Basic PHP Syntax A PHP scripting block always starts 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. For maximum compatibility, we recommend that you use the standard form (<?php) rather than the shorthand form.

–standard tags “ ”; –short tags “ ”; –ASP tags “ ”; –script tags “ ”.

<?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: <?php echo "Hello World"; ?>

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. <?php //This is a comment /* This is a comment block */ ?>

Variables in PHP Variables are used for storing a values, like text strings, numbers or arrays. When a variable is declared, it can be used over and over again in your script. All variables in PHP start with a $ sign symbol. The correct way of declaring a variable in PHP: $var_name = value; Let's try creating a variable containing a string, and a variable containing a number: <?php $txt="Hello World!"; $x=16; ?>

PHP is a Freely Typed Language In PHP, a variable does not need to be declared before adding a value to it. In the example above, you see that you do not have to tell PHP which data type the variable is. PHP automatically converts the variable to the correct data type, depending on its value. In a strongly typed programming language, you have to declare (define) the type and name of the variable before using it. In PHP, the variable is declared automatically when you use it.

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, A-Z, 0-9, and _ ) A variable name should not contain spaces. If a variable name is more than one word, it should be separated with an underscore ($my_string), or with capitalization ($myString)

PHP Test <?php echo " Hello World “,”Tanvi”; echo phpinfo(); ?>

A call to the phpinfo() function returns a lot of useful information about your system and setup such as available predefined variables, loaded PHP modules, and configuration settings.

How PHP code is Parsed

What happens to HTML Pages?

When a request for a page comes from the browser, the web server performs three steps: ❑ Read the request from the browser. ❑ Find the page in the server. ❑ Send the page back across the Internet to the browser.

What happens to PHP pages?

❑ Read the request from the browser. ❑ Find the page in the server. ❑ Perform any instructions provided in PHP to modify the page. ❑ Send the page back across the Internet to the browser.

Embedding PHP and HTML Following is an example of how PHP is embedded: My first PHP Page This is normal HTML code <?php // php code goes here ?> Back into normal HTML

PHP will only process things that are enclosed within one of its valid code blocks (such as ). Because of this, PHP effectively ignores everything that it was not specifically told to process and can be used to our advantage. For example, what will the output from the following be?

<?php $var = 5; ?> $var = 10; The variable $var has a value of: <?php =$var ?>

O/P: $var = 10; The variable $var has a value of: 5 Notice that with the second assignment of $var, when we attempt to change the value from 5 to 10, it has no effect because it is not enclosed within valid PHP code-block syntax. So, instead of being processed, it is simply displayed to the web browser.

Embedded conditionals... HTML CODE HTML CODE HTML CODE...

... HTML CODE...

<?php $n=-2; if($n==0): ?> zero <?php endif; if($n>0):?> positive.... <?php endif; if ($n Nage

PHP Data Types A data type refers to the type of data a variable can store. PHP has eight (8) different data types you can work with. These are: 1.integer numbers 2.floating point numbers 3.strings 4.booleans 5.arrays 6.objects 7.resouces 8.null

Integers An integer is a whole number. That is to say, it is a number with no fractional component. For those who are familiar with C, a PHP integer is the same as the long data type in C. It is a number between -2,147,483,648 and +2,147,483,647. decimal: a base ten numbering system Integers can be written in decimal, octal, or hexadecimal. Decimal numbers are a string of digits with no leading zeros. Any integer may begin with a plus sign ( + ) or a minus sign ( - ) to indicate whether it is a positive or negative number. If there is no sign, then positive is assumed.

Valid decimal integers: Valid octal integers: Valid hexadecimal integers: 0x1 0xff 0x1a3 +0x7 -0x1ab7345

Floating Point Numbers Floating-point numbers are also sometimes called real numbers. They are numbers that have a fractional component. Unlike basic math, all fractions are represented as decimal numbers. If you are familiar with C, PHP floating-point numbers are equivalent to the double data type. Floating-point numbers get their name from their decimal point. When using scientific notation to represent the number, the point floats in relation to the exponent being applied to the numeric component of the notation.

PHP recognizes two types of floating point numbers. The first is a simple numeric literal with a decimal point. The second is a floating-point number written in scientific notation. Scientific notation takes the form of [number]E[exponent], for example, 1.75E-2. Some examples of valid floating point numbers include: E2 // E-5 // E-3 //

Strings A string is a text literal of an arbitrary length. Most of working with Web pages is about working with strings. A string is indicated by being enclosed in quotes, either double or single quotes. $myVar = "xyz"; // assign a value to $myVar echo $myVar; // writes 'xyz' echo "abc to $myVar"; // writes 'abc to xyz‘ // but with single quotes echo 'abc to $myVar': // writes 'abc to $myVar'

Booleans A boolean value assesses the truth value of something. Booleans only have two values, true and false. These two values are represented by the keyword literals of the same name. All conditionals return a true/false boolean value based on the condition being tested.

Object An object is a data type that allows for the storage of not only data but also information on how to process that data. PHP is capable of functioning as an object-oriented programming language (or OOP).

Arrays An array is a variable that holds a group of values. Arrays are usually meant to store a collection of related data elements, although this is not a necessity. You access the individual elements by referring to their index position within the array. The position is either specificied numerically or by name

$arrName=array( key => value,... ) // key may be an integer or string // value may be any value OR $arr[key] = value; $arr[] = value; // key may be an integer or string // value may be any value

<?php $a=array(‘xyz’=>38,2=>23); /*$a[1] = "32"; $a['Quagmire'] = "30"; $a['Joe'] = "34";*/ echo "Peter is ". $a[2]. " years old."; ?>

"bar", 12 => true); echo $arr["foo"]; // bar echo $arr[12]; // 1 ?>

NULL Null is a special data type which can have only one value, which is itself. Which is to say, null is not only a data type, but also a keyword. A variable of data type null is a variable that has no value assigned to it. When a variable is created without a value, it is automatically assigned a value of null.

Resources OR References References in PHP are a means to access the same variable content by different names. PHP references allow you to make two variables to refer to the same content. Meaning, when you do: It means that $a and $b point to the same variable.

When you unset the reference, you just break the binding between variable name and variable content. This does not mean that variable content will be destroyed. For example: won't unset $b, just $a.

Variable Functions 1. is_array():- Finds whether a variable is an array Description:- is_array ( var) Returns TRUE if var is an array, FALSE otherwise.

2. is_float() -- Finds whether a variable is a float Description;- is_float (var) Returns TRUE if var is a float, FALSE otherwise. 3. is_int() -- Find whether a variable is an integer Description:- is_int (var) Returns TRUE if var is an integer FALSE otherwise.

4. is_string() -- Finds whether a variable is a string Description:- is_string (var) Returns TRUE if var is a string, FALSE otherwise. 5. is_object() -- Finds whether a variable is an object Description:- is_object (var) Returns TRUE if var is an object, FALSE otherwise.

6. is_bool() -- Finds out whether a variable is a boolean Description:- is_bool (var) Returns TRUE if the var parameter is boolean. 7. is_null -- Finds whether a variable is NULL Description:- is_null (var) Returns TRUE if var is null, FALSE otherwise. See the null type when a variable is considered to be NULL and when not.

Operators Arithmetic : +,-,/,%,* Assignment operators for all above operators. +=, -= etc, ++, -- Comparision ==, !=, <>, >, >=, <, <=, === === returns true if its two operands are having the same value, and they are of the same type. e.g. $a=15; $b=15; if( $a === $b) { print “Identical variables”; }

<?php $a=10; $b=10; if($a===$b) { print " Identical variables "; } ?>

Example Name Result $a == $b Equal TRUE if $a is equal to $b. $a === $b Identical TRUE if $a is equal to $b, and they are of the same type. (PHP 4 only) $a != $b Not equal TRUE if $a is not equal to $b. $a <> $b Not equal TRUE if $a is not equal to $b. $a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type. (PHP 4 only) $a < $b Less than TRUE if $a is strictly less than $b. $a > $b Greater than TRUE if $a is strictly greater than $b. $a <= $b Less than or equal to TRUE if $a is less than or equal to $b. $a >= $b Greater than or equal to TRUE if $a is greater than or equal to $b.

Global Variables a global variable can be accessed in any part of the program. However, in order to be modified, a global variable must be explicitly declared to be global in the function in which it is to be modified. This is accomplished, conveniently enough, by placing the keyword GLOBAL in front of the variable that should be recognized as global.

Placing this keyword in front of an already existing variable tells PHP to use the variable having that name. Consider an example: <?php $somevar = 15; function addit() { GLOBAL $somevar; $somevar++; print "Somevar is $somevar"; }

function addit1() { GLOBAL $somevar; $somevar++; print "Somevar is $somevar"; } addit(); addit1();?> O/P:- Somevar is 16

Static variables A static variable retains its value between calls to a function but is visible only within that function. You declare a variable static with the static keyword. For example: function update_counter

<?php function update_counter ( ) { static $counter = 0; $counter++; echo "Static counter is now $counter"; } $counter = 10; update_counter( ); echo “counter is $counter"; ?>

O/P:- Static counter is now 1 Static counter is now 2 Global counter is 10