Web Programming Language

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Everyday Italian Giada De Laurentiis Harry Potter J K. Rowling Learning XML Erik T. Ray CSCI 305 Introduction to Database.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
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.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
Advance Database Management Systems Lab no. 5 PHP Web Pages.
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.
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:
INTERNET APPLICATION DEVELOPMENT For More visit:
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
PHP By Jonathan Foss.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
PHP - Introduction Week 5 Dr. Ken Cosh Introducing PHP 1.
Web Programming Language Week 5 Dr. Ken Cosh Introducing PHP 1.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
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 Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms.
Introduction to PHP.
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.
COSC 2328 – Web Programming.  PHP is a server scripting language  It’s widely-used and free  It’s an alternative to Microsoft’s ASP and Ruby  PHP.
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.
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.
Simple PHP Web Applications Server Environment
A pache M ySQL P hp Robert Mudge Reference:
PHP using MySQL Database for Web Development (part II)
Web Systems & Technologies
CGS 3066: Web Programming and Design Spring 2017
Session 2 Basics of PHP.
>> Fundamental Concepts in PHP
Expressions and Control Flow in PHP
CS 371 Web Application Programming
CHAPTER 5 SERVER SIDE SCRIPTING
เอกสารประกอบการบรรยายรายวิชา Web Technology
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
DBW - PHP DBW2017.
Web Technologies PHP 5 Basic Language.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP Hypertext Preprocessor
Introduction to Web programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
8th Semester, Batch 2008 Department of Computer Science SSUET.
PHP Introduction.
PHP FORM HANDLING Post Method
Introduction to Web programming
Basic PHP Lecture by Nutthapat Keawrattanapat
Web Systems Development (CSC-215)
Software Engineering for Internet Applications
PHP: Basics FdSc Module 109 Server side scripting and Database design
PHP.
Web DB Programming: PHP
Web Programming Language
String functions
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
elementary programming
Intro to PHP.
PHP Forms and Databases.
PHP an introduction.
PHP Lecture 11 Kanida Sinmai
String functions
PHP-II.
Introduction to PHP.
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:

Web Programming Language Chapter 4

Introducing PHP Setting Up a Web Server PHP Basic Syntax PHP Variables PHP Operators PHP Flow Control PHP Form Validation

PHP “Hypertext Pre Processor” Common Server-side language powering 80% of websites Core Part of WAMP stack (Windows Apache MySQL PHP) Or LAMP, or MAMP

Set Up A Webserver If you already have a webserver – great! If not, set up your local machine as a host, by installing wampserver. Create a file called hello.php in your www folder <?php echo “Hello World” ?> Open it in a browser; localhost/hello.php or 127.0.0.1/hello.php

PHP Variables Begin with $ Named by any combination of letters, numbers, and _ $Name Case Sensitive $NAME, $Name, $name are different variables Can store different types of data Strings, Integers, Floats, Boolean, Array & Objects Weakly Typed You don’t need to specify which type of data the variable will store No need for declaration

PHP Variables Opening PHP Tag <?php $x = 5; $y = “3.5”; $z = $x + $y; echo "The number is $z<br>"; echo "The number is " . $z . "<br>"; ?> Assignment Addition Output Concatenation Closing PHP Tag

Arrays Creates an Indexed array where “John” has index 0, and Fred has index 3. <?php $students = array(“John”, “Bob”, “Steve”); $students[] = “Fred”; echo “The first student is “ . $students[0]; ?>

Associative Arrays The Index could be a string <?php $ages = array(“John”=>”18”, “Bob”=>”19”, “Steve”=>”22”); echo “John is “ . $ages[“John”]; ?> Each element is a “Key=>Value” Pair

Multidimensional Arrays A 2 dimensional array is just an Array of Arrays <?php $students = array(); $students[] = array("John", "84", "A"); $students[] = array("Bob", "65", "C+"); $students[] = array("Steve", "72", "B"); echo "The first student's grade is " . $students[0][2]; ?>

Strings Strings are important in PHP (we are dealing with text on the web of course!) Function Name Purpose explode() Splits a string into an array implode() Converts an array into a string lcfirst() Makes the first character of a string lowercase str_replace() Replaces specified characters in a string str_word_count() Returns the number of words in the string strcmp() Compares two strings strlen() Returns the length of a string strpos() Returns the position of the first occurrence of a string inside another string strtoupper() Converts a string to upper case strtolower() Converts a string to lower case substr() Returns a specified part of a string ucfirst() Makes the first character of a string uppercase

PHP Operators (Arithmetic) Arithmetic Operators Purpose Example + Addition $x=1+2; - Subtraction $x=2-1; * Multiplication $x=1*2; / Division $x=2/1; % Modulus Returns the remainder from a division $x=2%1; ++ Increment (add one to the value) $x++; -- Decrement (minus one from the value) $x--;

PHP Operators (Assignment) Assignment Operators Example Equivalent = $a = $b;   += $a += $b; $a = $a + $b; -= $a -= $b; $a = $a – $b; *= $a *= $b; $a = $a * $b; /= $a /= $b; $a = $a / $b; %= $a %= $b; $a = $a % $b; .= $a .= $b $a = $a . $b;

PHP Operators (Logical) Logical Operators Purpose == Equal to != Not equal to <>  <  Less than >  Greater than <= Less than or equal to >= Greater than or equal to && AND || OR ! Not

PHP Flow Control (IF) <?php if($x>20) { echo “x is greater than 20”; } elseif($x<10) { echo “x is smaller than 20”; } else { echo “x is between 10 and 20”; } ?>

PHP Flow Control (Switch) <?php switch ($x) { case “login”: echo “Display the Login Page”; break; case “register”: echo “Display the Register Page”; break; default: echo “Display the Guest Page”; break; } ?>

PHP Flow Control (While) <?php $x = 10; while($x>0) { echo “There were “ . $x . “ in the bed, till someone said, roll over…<br>”; $x--; } ?>

PHP Flow Control (Do…While) <?php $x = 10; do { echo “There were “ . $x . “ green apples, ready to be eaten…<br>”; $x--; } while($x>0); ?>

PHP Flow Control (For) <?php for($i = 0; $i<10; $i++) { echo “I have “ . $i . “ doors, but need 1 more…<br>”; } ?>

PHP Flow Control (Foreach) <?php $count = 1; foreach($students as $name) { echo $count . “) Student name:- “ . $name . “<br>”; $count++; } ?>

PHP Flow Control (Foreach) Associative <?php $count = 1; foreach($students as $name => $grade) { echo $count . “) Student “ . $name . “ got grade “ . $grade . “<br>”; $count++; } ?>

PHP Form Validation HTML’s <form> tag is used to create a form that can send data to the server. <form action="welcome.php" method="post"> Name: <input type="text" name="name"><br /> <input type="submit" value="Go!"> </form>

$_POST The previous form sends data by the POST method to welcome.php <body> Welcome <?php echo $_POST[“name”]; ?> </body>

$_GET An alternative is to send the data via the GET method <form action="welcome.php" method="get"> Name: <input type="text" name="name"><br /> <input type="submit" value="Go!"> </form> <body> Welcome <?php echo $_GET[“name”]; ?> </body> What is the difference?

$_POST or $_GET Both arrays are Superglobals, accessible from any function, class or file on the page. Both create an array of key=>value pairs with the names of the form inputs and the values submitted The GET method passes variables via URL parameters, while POST passes it via HTTP Post method. The GET method is visible, so should not be used for sensitive data, but because it is visible, it can be bookmarked. However the URL is limited to around 2,000 characters.

print_r() A useful function for making a human readable version of an array <body> <?php print_r($_POST); ?> </body>

Simple Form Validation <body> <?php $name = $_POST["name"]; if(strlen($name)<3) { echo "Name must be at least 3 characters."; } ?> </body>

Key Points PHP is an important Server Side programming language. Before running PHP code a web server needs to be set up to process PHP code. When a web server receives a request for PHP, first it processes the code before returning HTML. Variables in PHP are weakly or loosely typed and can also be used to store arrays. A form can be used to send data to the server using the post method. Data sent via the post method then exists within the $_POST superglobal array, or using the get method to the $_GET superglobal array. The main difference between post and get is that when using get, the parameters are attached to the url, so that it can be bookmarked.