เอกสารประกอบการบรรยายรายวิชา Web Technology

Slides:



Advertisements
Similar presentations
2012 •••••••••••••••••••••••••••••••••• Summer WorkShop Mostafa Badr
Advertisements

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.
04/09/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
IDK0040 Võrgurakendused I harjutus 07: PHP: Operators, Switch, Forms Deniss Kumlander.
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 Tutorial By RAY BALIKI && ROY GHORAYEB. DEFINITION PHP is a powerful server-side scripting language for creating dynamic and interactive websites.
CP3024 Lecture 3 Server Side Facilities. Lecture contents  Server side includes  Common gateway interface (CGI)  PHP Hypertext Preprocessor (PHP) pages.
INTERNET APPLICATION DEVELOPMENT For More visit:
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
INTERNET APPLICATION DEVELOPMENT For More visit:
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Nael Alian Introduction to PHP
PHP - Introduction Week 5 Dr. Ken Cosh Introducing PHP 1.
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.
PHP Conditional Statements Conditional statements in PHP are used to perform different actions based on different conditions. Conditional Statements Very.
Web Programming Language Week 5 Dr. Ken Cosh Introducing PHP 1.
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?
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.
PHP Constructs Advance Database Management Systems Lab no.3.
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.
Introduction to PHP Brendan Knight. What is PHP PHP is a general-purpose scripting language originally designed for web development to produce dynamic.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
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.
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 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:
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
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.
Click to edit Master subtitle style 03/02/11 Web And Coding Club IIT Bombay PHP (pre hypertext processor) By: Saurabh Goyal Apekshit Sharma.
PHP using MySQL Database for Web Development (part II)
CGS 3066: Web Programming and Design Spring 2017
Session 2 Basics of PHP.
>> Fundamental Concepts in PHP
CHAPTER 5 SERVER SIDE SCRIPTING
Chapter 5 Scripting Language
CS 371 Web Application Programming
CHAPTER 5 SERVER SIDE SCRIPTING
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
PHP 5 Syntax.
Web Technologies PHP 5 Basic Language.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
1 CHAPTER 10 ADVANCED PHP.
PHP Hypertext Preprocessor
Introduction to Web programming
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
JavaScript Syntax and Semantics
Chapter 5 Scripting Language
8th Semester, Batch 2008 Department of Computer Science SSUET.
PHP Introduction.
Basic PHP Lecture by Nutthapat Keawrattanapat
PHP.
Basics.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Basics (Cont...).
Decisions, Loops, and Arrays
Web Programming Language
Tutorial 6 PHP & MySQL Li Xu
PHP an introduction.
PHP PROF. S. LAKSHMANAN, DEPT. OF B. VOC. (SD & SA),
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:

เอกสารประกอบการบรรยายรายวิชา 204329 Web Technology Basic PHP syntax

Web Architecture Web Browser Host Web Server

หัวข้อบรรยาย PHP Recap PHP Example Applications Basic PHP Syntax Variables, I/O, String Operations, Control Statements, Forms

Web Architecture Apache Web server Apache Tomcat Internet Information Server Netscape Web Server

Web Architecture Web Browser Host Web FTP Mail

Web Architecture Client Host Browser Web FTP Mail

Common Gateway Interface (CGI) Web Browser Web Server Request Object

Common Gateway Interface (CGI) Web Browser Web Server Response Object

Common Gateway Interface (CGI) printf(“<HTML>”); printf(“<BODY>”); printf(“Hello CGI<BR>”); printf(“1 + 1 = %d”, 1+1); printf(“</BODY>”); printf(“</HTML>”);

Common Gateway Interface (CGI)

Common Gateway Interface (CGI) Web Browser Web Server Response Object

Common Gateway Interface (CGI) printf(“<HTML>”); printf(“<BODY>”); printf(“Hello CGI<BR>”); printf(“1 + 1 = &d”, 1+1); printf(“</BODY>”); printf(“</HTML>”);

Common Gateway Interface (CGI) Web Browser Web Server <HTML> <BODY> Hello CGI<BR> 1+1=2 </BODY> </HTML>

Common Gateway Interface (CGI)

Common Gateway Interface (CGI) C/C++ Perl

Common Gateway Interface (CGI) $sum = 1 + 1 print “<HTML>”; print “<BODY>”; print “Hello Perl<BR>”; print “1 + 1 = $sum” print “</BODY>” ; print “</HTML>”;

Common Gateway Interface (CGI)

หลักการทำงานของ PHP Web Browser Web Server App. Engine

หลักการทำงานของ PHP Web Browser Web Server App. Engine

หลักการทำงานของ ASP & PHP <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> <?php echo "Hello ASP<BR />"; echo "1 + 1 = " . (1+1); ?> </BODY> </HTML>

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> <?php echo "Hello ASP<BR />"; echo "1 + 1 = " . (1+1); ?> </BODY> </HTML> PHP Engine

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> <?php echo "Hello ASP<BR />"; echo "1 + 1 = " . (1+1); ?> </BODY> </HTML> PHP Engine

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> <?php echo "Hello ASP<BR />"; echo "1 + 1 = " . (1+1); ?> </BODY> </HTML> PHP Engine

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> <?php echo "Hello ASP<BR />"; echo "1 + 1 = " . (1+1); ?> </BODY> </HTML> PHP Engine

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> Hello ASP<BR> 1 + 1 = 2 </BODY> </HTML> PHP Engine

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> Hello ASP<BR> 1 + 1 = 2 </BODY> </HTML> PHP Engine

หลักการทำงานของ ASP & PHP Web Browser Web Server Example Hello Bold Hello Italic Hello ASP 1 + 1 = 2 PHP Engine

หลักการทำงานของ ASP & PHP <HTML> <BODY> <H1>Example</H1> <B>Hello Bold</B><BR> <B>Hello Italic</B><BR> <?php echo "Hello ASP<BR />"; echo "1 + 1 = " . (1+1); ?> </BODY> </HTML>

หลักการทำงานของ ASP & PHP Web Browser Web Server Request Object

หลักการทำงานของ ASP & PHP Web Browser Web Server Response Object

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <IMG SRC="images/SUTLogo.JPG"> <BR> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> Hello ASP <BR> 1+1=2 </BODY> </HTML> <HTML> <BODY> <H1>Example</H1> <IMG SRC="images/SUTLogo.JPG"> <BR> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> <?php echo "Hello ASP<BR />"; echo "1 + 1 = " . (1+1); ?> </BODY> </HTML>

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <H1>Example</H1> <IMG SRC="images/SUTLogo.JPG"> <BR> <B>Hello Bold</B><BR> <I>Hello Italic</I><BR> Hello ASP <BR> 1+1=2 </BODY> </HTML>

หลักการทำงานของ ASP & PHP Web Browser Web Server

Form & ASP/PHP

หลักการทำงานของ ASP & PHP Web Browser Web Server Request Object

Form & ASP/PHP <html> <body> <form action="demo_simpleform.php" method="post"> Your name: <input type="text" name="fname" size="20"> <input type="submit" value="Submit"> </form> <?php if($_POST["fname"] != null) { echo "Hello " . $_POST["fname"]; echo "<BR />How are you today?"; } ?> </body> </html>

หลักการทำงานของ ASP & PHP Web Browser Web Server Request Object

หลักการทำงานของ ASP & PHP <html> <body> <form action="demo_simpleform.asp" … $_POST["fname"]; … </body> </html> Web Browser Web Server Form { action=“demo…” fname=“john” }

หลักการทำงานของ ASP & PHP Web Browser Web Server <html> <body> <form> … </form> <?php if($_POST["fname"] != null) { echo "Hello " . $_POST["fname"]; echo "<BR />How are you today?"; } ?> </body> </html> Response Object

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <FORM …> … </FORM> Hello John<BR> How are you today? </BODY> </HTML> <html> <body> <form> … </form> <?php if($_POST["fname"] != null) { echo "Hello " . $_POST["fname"]; echo "<BR />How are you today?"; } ?> </body> </html>

หลักการทำงานของ ASP & PHP Web Browser Web Server <HTML> <BODY> <FORM …> … </FORM> Hello John<BR> How are you today? </BODY> </HTML>

หลักการทำงานของ ASP & PHP Web Browser Web Server

หลักการทำงานของ ASP & PHP Web Browser Web Server Request Object

หลักการทำงานของ ASP & PHP Web Browser Web Server Response Object

PHP & Database Web Browser Web Server Database PHP Engine

หัวข้อบรรยาย PHP Recap PHP Example Applications Basic PHP Syntax Variables, I/O, String Operations, Control Statements, Forms

หัวข้อบรรยาย PHP Recap PHP Example Applications Basic PHP Syntax Variables, I/O, String Operations, Control Statements, Forms

Basic PHP Syntax Variables I/O String Operations Control Statements Forms

Basic PHP Syntax <?php ?>

Basic PHP Syntax A PHP scripting block always starts with <?php and ends 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 <? and end with ?>.

Basic PHP Syntax <html> <body> <?php echo "Hello World"; ?> </body> </html>

Basic PHP Syntax Comments in PHP In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.

Basic PHP Syntax <html> <body> <?php //This is a comment /* This is a comment block */ ?> </body> </html>

Basic PHP Syntax Variables in PHP Variables are used for storing a values, like text strings, numbers or arrays. When a variable is set it can be used over and over again in your script All variables in PHP start with a $ sign symbol. The correct way of setting a variable in PHP: $var_name = value;

Basic PHP Syntax New PHP programmers often forget the $ sign at the beginning of the variable. In that case it will not work. Let's try creating a variable with a string, and a variable with a number: <?php $txt = "Hello World!"; $number = 16; ?>

Basic PHP Syntax PHP is a Loosely Typed Language In PHP a variable does not need to be declared before being set.

Basic PHP Syntax Variable Naming Rules A variable name must start with a letter or an underscore "_" A variable name can only contain alpha-numeric characters and underscores (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 underscore ($my_string), or with capitalization ($myString)

Basic PHP Syntax Strings in PHP String variables are used for values that contains character strings. <?php $txt="Hello World"; echo $txt; ?>

Basic PHP Syntax The Concatenation Operator There is only one string operator in PHP. The concatenation operator (.)  is used to put two string values together. To concatenate two variables together, use the dot (.) operator:

Basic PHP Syntax <?php $txt1="Hello World"; $txt2="1234"; echo $txt1 . " " . $txt2; ?>

Basic PHP Syntax Using the strlen() function The strlen() function is used to find the length of a string. Let's find the length of our string "Hello world!": <?php echo strlen("Hello world!"); ?>

Basic PHP Syntax Using the strpos() function The strpos() function is used to search for a string or character within a string. If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE. Let's see if we can find the string "world" in our string: <?php echo strpos("Hello world!","world"); ?> Etc.

Basic PHP Syntax PHP Operators Arithmetic Operators

Basic PHP Syntax PHP Operators Assignment Operators

Basic PHP Syntax PHP Operators Comparison Operators

Basic PHP Syntax PHP Operators Logical Operators

Basic PHP Syntax Conditional Statements 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. if...else statement - use this statement if you want to execute a set of code when a condition is true and another if the condition is not true elseif statement - is used with the if...else statement to execute a set of code if one of several condition are true

Basic PHP Syntax The If...Else Statement If you want to execute some code if a condition is true and another code if a condition is false, use the if....else statement. Syntax if (condition) code to be executed if condition is true; else code to be executed if condition is false;

<html> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; else echo "Have a nice day!"; ?> </body> </html>

<html> <body> <?php $d=date("D"); if ($d=="Fri") { echo "Hello!<br />"; echo "Have a nice weekend!"; echo "See you on Monday!"; } ?> </body> </html>

Basic PHP Syntax The ElseIf Statement If you want to execute some code if one of several conditions are true use the elseif statement Syntax if (condition) code to be executed if condition is true; elseif (condition) else code to be executed if condition is false;

<html> <body> <?php $d=date("D"); if ($d=="Fri") echo "Have a nice weekend!"; elseif ($d=="Sun") echo "Have a nice Sunday!"; else echo "Have a nice day!"; ?> </body> </html>

Basic PHP Syntax Looping Very often when you write code, you want the same block of code to run a number of times. You can use looping statements in your code to perform this. In PHP we have the following looping statements: while - loops through a block of code if and as long as a specified condition is true do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true for - loops through a block of code a specified number of times

Basic PHP Syntax While Statement <html> <body> <?php while($i<=5) { echo "The number is " . $i . "<br />"; $i++; } ?> </body> </html>

Basic PHP Syntax Do…While Statement <html> <body> <?php { $i++; echo "The number is " . $i . "<br />"; } while ($i<5); ?> </body> </html>

Basic PHP Syntax The for Statement <html> <body> <?php for ($i=1; $i<=5; $i++) { echo "Hello World!<br />"; } ?> </body> </html>

Basic PHP Syntax The foreach Statement <html> <body> $arr=array("one", "two", "three"); foreach ($arr as $value) { echo "Value: " . $value . "<br />"; } ?> </body> </html>

Basic PHP Syntax PHP Form Handling The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.

form.php <html> <body><form action="welcome.php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form></body> </html>

welcome.php <html> <body>Welcome <?php echo $_POST["name"]; ?>.<br /> You are <?php echo $_POST["age"]; ?> years old.</body> </html>

Basic PHP Syntax PHP Form Handling $_GET $_POST

Basic PHP Syntax $_GET <form action="welcome.php" method="get"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form>

Basic PHP Syntax $_GET welcome.php Welcome <?php echo $_GET["name"]; ?>.<br /> You are <?php echo $_GET["age"]; ?> years old!

Basic PHP Syntax $_POST <form action="welcome.php" method="post"> Enter your name: <input type="text" name="name" /> Enter your age: <input type="text" name="age" /> <input type="submit" /> </form>

Basic PHP Syntax $_POST Welcome <?php echo $_POST["name"]; ?>.<br /> You are <?php echo $_POST["age"]; ?> years old!

The $_REQUEST Variable The PHP $_REQUEST variable contains the contents of both $_GET, $_POST Example Welcome <?php echo $_REQUEST["name"]; ?>.<br /> You are <?php echo $_REQUEST["age"]; ?> years old!

หัวข้อบรรยาย PHP Recap PHP Example Applications Basic PHP Syntax Variables, I/O, String Operations, Control Statements, Forms

หัวข้อบรรยาย PHP Recap PHP Example Applications Basic PHP Syntax Variables, I/O, String Operations, Control Statements, Forms