PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

+ Intro to PHP and SQL James Ohene-Djan. + What We’ll Cover Introduction to PHP Explain example code Introduction to Database Using PHP/MySQL for database.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
The Web Warrior Guide to Web Design Technologies
Everyday Italian Giada De Laurentiis Harry Potter J K. Rowling Learning XML Erik T. Ray CSCI 305 Introduction to Database.
PHP The Basic PHP. Out line o History of PHP o What is PHP? o Why PHP ? o What you need to start using PHP ? o What does PHP code look like? o Syntax.
Introduction to Database
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Guide To UNIX Using Linux Third Edition
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.
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Types of websites (PHP basics). Website  A website, also written Web site, web site, or simply site, is a collection of related web pages containing.
PHP The Basic. Outline  History of PHP  What is PHP?  What does PHP code look like?  Apache Server.  Syntax PHP code.  Anatomy of a PHP Script.
8/17/2015CS346 PHP1 Module 1 Introduction to PHP.
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”
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.
PHP: Hypertext Processor Fred Durao
CSC 318 WEB APPLICATION DEVELOPMENT.  Introduction to Server Scripting language  Client VS Server  Introduction to PHP  PHP Files and Syntax  Function.
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.
Copyright © Curt Hill PhP History and Introduction.
CSC 405: Web Application And Engineering II 2.1 Web Programming with PHP Introduction to Web programming Introduction to Web programming The programming.
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
Introduction to Database. What is PHP? PHP == ‘PHP Hypertext Preprocessor’ Open-source, server-side scripting language Used to generate dynamic web-pages.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
Nael Alian Introduction to PHP
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
10/5/2015CS346 PHP1 Module 1 Introduction to PHP.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Variables and ConstantstMyn1 Variables and Constants PHP stands for: ”PHP: Hypertext Preprocessor”, and it is a server-side programming language. Special.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
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.
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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
By Mr. Muhammad Pervez Akhtar
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
CSC 405: Web Application Engineering II 2.1 Web Programming with PHP Introduction to Web programming Introduction to Web programming The programming language.
PHP/MySQL Tutorial Introduction to Database Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
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.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
CHAPTER 5 SERVER SIDE SCRIPTING
Web Database Programming Using PHP
PHP (PHP: Hypertext Preprocessor)
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
PHP Introduction.
Intro to PHP & Variables
PHP.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Web DB Programming: PHP
Basics.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Presentation transcript:

PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP tags  This allows the programmer to embed PHP scripts within HTML pages What is PHP?

What is PHP (cont’d) Interpreted language, scripts are parsed at run- time rather than compiled beforehand Executed on the server-side Source-code not visible by client  ‘ View Source ’ in browsers does not display the PHP code Various built-in functions allow for fast development Compatible with many popular databases

What does PHP code look like? Structurally similar to C/C++ Supports procedural and object-oriented paradigm (to some degree) All PHP statements end with a semi-colon Each PHP script must be enclosed in the reserved PHP tag <?php … ?>

Comments in PHP Standard C, C++, and shell comment symbols // C++ and Java-style comment # Shell-style comments /* C-style comments These can span multiple lines */

Variables in PHP PHP variables must begin with a “ $ ” sign Case-sensitive ($Foo != $foo != $fOo) Global and locally-scoped variables  Global variables can be used anywhere  Local variables restricted to a function or class Certain variable names reserved by PHP  Form variables ($_POST, $_GET)  Server variables ($_SERVER)  Etc.

Variable usage <?php $foo = 25;// Numerical variable $bar = “Hello”;// String variable $foo = ($foo * 7);// Multiplies foo by 7 $bar = ($bar * 7);// Invalid expression ?>

Echo The PHP command ‘ echo ’ is used to output the parameters passed to it  The typical usage for this is to send data to the client ’ s web-browser Syntax  void echo (string arg1 [, string argn...])  In practice, arguments are not passed in parentheses since echo is a language construct rather than an actual function

Echo example Notice how echo ‘ 5x5=$foo ’ outputs $foo rather than replacing it with 25 Strings in single quotes ( ‘ ’ ) are not interpreted or evaluated by PHP This is true for both variables and character escape-sequences (such as “ \n ” or “ \\ ” ) <?php $foo = 25;// Numerical variable $bar = “Hello”;// String variable echo $bar;// Outputs Hello echo $foo,$bar;// Outputs 25Hello echo “5x5=”,$foo;// Outputs 5x5=25 echo “5x5=$foo”;// Outputs 5x5=25 echo ‘5x5=$foo’;// Outputs 5x5=$foo ?>

Arithmetic Operations $a - $b // subtraction $a * $b// multiplication $a / $b// division $a += 5// $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; Print $total; Print “ $total ”; // total is 45 ?>

Concatenation Use a period to join strings into one. <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1. “ ”. $string2; Print $string3; ?> Hello PHP

Escaping the Character If the string has a set of double quotation marks that must remain visible, use the \ [backslash] before the quotation marks to ignore and display them. <?php $heading=“\”Computer Science\””; Print $heading; ?> “Computer Science”

PHP Control Structures  Control Structures: Are the structures within a language that allow us to control the flow of execution through a program or script.  Grouped into conditional (branching) structures (e.g. if/else) and repetition structures (e.g. while loops).  Example if/else if/else statement: if ($foo == 0) { echo ‘The variable foo is equal to 0’; } else if (($foo > 0) && ($foo <= 5)) { echo ‘The variable foo is between 1 and 5’; } else { echo ‘The variable foo is equal to ‘.$foo; }

If... Else... If (condition) { Statements; } Else { Statement; } <?php If($user==“John”) { Print “Hello John.”; } Else { Print “You are not John.”; } ?> No THEN in PHP

While Loops While (condition) { Statements; } <?php $count=0; While($count<3) { Print “hello PHP. ”; $count += 1; // $count = $count + 1; // or // $count++; ?> hello PHP. hello PHP. hello PHP.

Date Display $datedisplay=date(“yyyy/m/d”); Print $datedisplay; # If the date is April 1 st, 2009 # It would display as 2009/4/1 2009/4/1 $datedisplay=date(“l, F m, Y”); Print $datedisplay; # If the date is April 1 st, 2009 # Wednesday, April 1, 2009 Wednesday, April 1, 2009

Month, Day & Date Format Symbols MJan FJanuary m01 n1 Day of Monthd01 Day of MonthJ1 Day of WeeklMonday Day of WeekDMon

Functions Functions MUST be defined before then can be called Function headers are of the format  Note that no return type is specified Unlike variables, function names are not case sensitive (foo( … ) == Foo( … ) == FoO( … )) function functionName($arg_1, $arg_2, …, $arg_n)

Functions example <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2; return $arg_2; } $result_1 = foo(12, 3);// Store the function echo $result_1;// Outputs 36 echo foo(12, 3);// Outputs 36 ?>

Include Files Include “opendb.php”; Include “closedb.php”; This inserts files; the code in files will be inserted into current code. This will provide useful and protective means once you connect to a database, as well as for other repeated functions. Include (“footer.php”); The file footer.php might look like: Copyright © KSU ALL RIGHTS RESERVED URL:

PHP - Forms Access to the HTTP POST and GET data is simple in PHPAccess to the HTTP POST and GET data is simple in PHP The global variables $_POST[] and $_GET[] contain the request dataThe global variables $_POST[] and $_GET[] contain the request data <?php if ($_POST["submit"]) echo " You clicked Submit! "; else if ($_POST["cancel"]) echo " You clicked Cancel! "; ?>

PHP Overview Easy learning Syntax Perl- and C-like syntax. Relatively easy to learn. Large function library Embedded directly into HTML Interpreted, no need to compile Open Source server-side scripting language designed specifically for the web.

Save as sample.php: Hello World! <?php echo “ Hello, World ” ; ?> <?php $myvar = "Hello World"; echo $myvar; ?> First PHP script

Functions mysqli_connect(host,username,password,db name); mysqli_close($con); mysqli_query($con,$sql) mysql_num_rows() mysql_fetch_array() Isset()