Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.

Similar presentations


Presentation on theme: "CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1."— Presentation transcript:

1 CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1

2 Content PHP 5 Introduction PHP 5 Syntax PHP 5 Variables PHP 5 echo and print Statements PHP 5 Data Types PHP 5 Strings PHP 5 Constants PHP 5 Operators 2

3 PHP 5 Introduction 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 to competitors such as Microsoft's ASP. 3 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 is free to download and use

4 PHP 5 Introduction (cont.) 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" 4

5 PHP 5 Introduction (cont.) What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, 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 be used to control user-access PHP can encrypt data 5 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: www.php.netwww.php.net PHP is easy to learn and runs efficiently on the server side

6 PHP 5 Syntax Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with : My first PHP page Note: PHP statements end with a semicolon (;). 6

7 PHP 5 Syntax (cont.) Comments in PHP 7

8 PHP 5 Syntax (cont.) PHP Case Sensitivity "; echo "Hello World! "; EcHo "Hello World! "; ?> 8 "; echo "My house is ". $COLOR. " "; echo "My boat is ". $coLOR. " "; ?> ?

9 PHP 5 Variables Creating (Declaring) PHP Variables 9 PHP Variables 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 ($age and $AGE are two different variables) Remember that PHP variable names are case-sensitive!

10 PHP 5 Variables (cont.) Output Variables 10 PHP Variables Scope PHP has three different variable scopes: local global static

11 PHP 5 Variables (cont.) Global and Local Scope Variable x inside function is: $x "; } myTest(); echo " Variable x outside function is: $x "; ?> 11

12 PHP 5 Variables (cont.) PHP The global Keyword 12 PHP The static Keyword

13 PHP 5 echo and print Statements PHP echo and print Statements PHP is Fun! "; print "Hello world! "; ?> 13

14 PHP 5 Data Types PHP Data Types PHP supports the following data types: String Integer Float (floating point numbers - also called double) Boolean Array Object NULL Resource 14

15 PHP 5 Data Types (cont.) PHP String 15 PHP Integer PHP Float PHP Boolean $x = true; $y = false;

16 PHP 5 Data Types (cont.) PHP Array 16 PHP Object model = "VW"; } } // create an object $herbie = new Car(); // show object properties echo $herbie->model; ?>

17 PHP 5 Data Types (cont.) PHP NULL Value 17

18 PHP 5 Strings Get The Length of a String 18 Count The Number of Words in a String Reverse a String Search For a Specific Text Within a String Replace Text Within a String

19 PHP 5 Constants Create a PHP Constant Syntax define(name, value, case-insensitive) Example 19

20 PHP 5 Operators PHP Operators Operators are used to perform operations on variables and values. PHP divides the operators in the following groups: Arithmetic operators Assignment operators Comparison operators Increment/Decrement operators Logical operators String operators Array operators 20

21 PHP 5 Operators (cont.) PHP Arithmetic Operators 21 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 ** Exponentiation$x ** $yResult of raising $x to the $y'th power (Introduced in PHP 5.6)

22 PHP 5 Operators (cont.) PHP Assignment Operators 22 AssignmentSame as...Description x = y The left operand gets set to the value of the expression on the right x += y x = x + yAddition x -= y x = x - ySubtraction x *= y x = x * yMultiplication x /= y x = x / yDivision x %= y x = x % yModulus

23 PHP 5 Operators (cont.) PHP Comparison Operators 23 OperatorNameExampleResult == Equal$x == $yReturns true if $x is equal to $y === Identical$x === $yReturns true if $x is equal to $y, and they are of the same type != Not equal$x != $yReturns true if $x is not equal to $y <> Not equal$x <> $yReturns true if $x is not equal to $y !== Not identical$x !== $yReturns true if $x is not equal to $y, or they are not of the same type > Greater than$x > $yReturns true if $x is greater than $y < Less than$x < $yReturns true if $x is less than $y >= Greater than or equal to $x >= $yReturns true if $x is greater than or equal to $y <= Less than or equal to $x <= $yReturns true if $x is less than or equal to $y

24 PHP 5 Operators (cont.) PHP Increment / Decrement Operators 24 OperatorNameDescription ++$xPre-incrementIncrements $x by one, then returns $x $x++Post-incrementReturns $x, then increments $x by one --$xPre-decrementDecrements $x by one, then returns $x $x--Post-decrementReturns $x, then decrements $x by one

25 PHP 5 Operators (cont.) PHP Logical Operators 25 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 String Operators OperatorNameExampleResult. Concatenation$txt1. $txt2Concatenation of $txt1 and $txt2.= Concatenation assignment $txt1.= $txt2Appends $txt2 to $txt1

26 PHP 5 Operators (cont.) PHP Array Operators 26 OperatorNameExampleResult + Union$x + $yUnion of $x and $y == Equality$x == $yReturns true if $x and $y have the same key/value pairs === Identity$x === $yReturns true if $x and $y have the same key/value pairs in the same order and of the same types != Inequality$x != $yReturns true if $x is not equal to $y <> Inequality$x <> $yReturns true if $x is not equal to $y !== Non-identity$x !== $yReturns true if $x is not identical to $y

27 27 THE END


Download ppt "CHAPTER 6 Introduction to PHP5 Part I อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1."

Similar presentations


Ads by Google