Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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. Know the fundamental concepts of Web Scripting Languages in general, PHP in particular. Make simple scripts with PHP: Make simple scripts with PHP: PHP Syntax PHP Syntax PHP Data Types PHP Data Types

2 2 PHP Intro Processing an HTTP Request 4 Client Browser 1 PHP Module Apache Web Server 23

3 3 PHP Intro Web Scripting Languages Languages used to create Web pages dynamically, e.g., by using data retrieved from a database: CGI Scripts and Programs CGI Scripts and Programs Perl: Practical Extraction and Report Language Perl: Practical Extraction and Report Language PHP: Hypertext Preprocessor PHP: Hypertext Preprocessor ASP: Server Pages ASP: Active Server Pages JSP: Java Server Pages JSP: Java Server Pages ASP.NET: Visual Basic, C# ASP.NET: Visual Basic, C# Python Python

4 4 PHP Intro What is PHP? PHP is a scripting language used mostly for creating web pages dynamically. PHP: Hypertext Preprocessor. Originally called Personal Home Page. PHP: Hypertext Preprocessor. Originally called Personal Home Page. PHP is server-side scripting. PHP is server-side scripting. PHP statements can be embedded within an ordinary HTML page with tags. PHP statements can be embedded within an ordinary HTML page with tags. PHP is dynamically typed. PHP is dynamically typed. PHP code is interpreted. PHP code is interpreted.

5 5 PHP Intro Simple PHP Script Output: 2 + 3 = 5 <?php $x = 2; $y = 3; $z = $x + $y; echo “2 + 3 = $z”; ?>

6 6 PHP Intro Simple PHP Web Script Hello World! <?php echo “Hello World!“; ?> Output: Hello World! Hello World!

7 7 PHP Intro PHP Syntax Similar to C++ / Java Semi-colon ; is a statement terminator. Semi-colon ; is a statement terminator. Variable names start with $. Variable names start with $. Operators and expressions are similar to those used by C and Java with a few additions. Operators and expressions are similar to those used by C and Java with a few additions. Control structures Control structures if-else, switch, while, do-while, for, foreach, break, continue,...

8 8 PHP Intro PHP Data types Scalar types: - boolean - integer - float (double) - string Compound types: - array - object Special types: - resource - NULL

9 9 PHP Intro Variables Are Not Statically Typed $A = 1; $A = “abc”; Since a variable is not statically typed, a value of any type can be assigned to it. The type of a variable can be boolean, integer, float, string, array, object, and resources. NULL also can be assigned.

10 10 PHP Intro Polymorphism: Automatic Data Type Conversion $A = 1; $B = 2; $C = $A + $B; $D = $A. $B; echo "$C\n"; echo "$D\n"; echo ’$C\n’; Output: 3 12 $C\n

11 11 PHP Intro Boolean Values echo true; echo false; echo 1; echo 0; echo true ? ‘A’ : ‘B’; echo 1 ? ‘A’ : ‘B’; echo 100 ? ‘A’ : ‘B’; echo ‘xx’ ? ‘A’ : ‘B’; echo false ? ‘A’ : ‘B’; echo 0 ? ‘A’ : ‘B’; echo ‘’ ? ‘A’ : ‘B’; 1(empty)10 AAAABBB

12 12 PHP Intro Idiosyncrasies echo ‘dog’ = = 0; echo 0 = = 0; echo 0 = = false; echo 0 = = = 0; echo 0 = = = false; echo ‘100’ = = 100; echo ‘100’ = = = 100; echo (int) “100”; echo (int) “100xxx”; echo (int) “xxx100”; 1111(empty)1(empty)1001000

13 13 PHP Intro Evaluating a Variable within Text Mode Evaluation: $x1 = 100 $x2 = 100 $x3 = 100 Evaluation: <? $x = 100; echo “ \$x1 = ”. $x; echo “ \$x2 = $x\n”; ?> $x3 =

14 14 PHP Intro Special Characters within “ …” The following special characters can be used within a string quoted by “”: \” -- double quote \” -- double quote \n -- newline \n -- newline \r -- carriage return \r -- carriage return \t -- tab \t -- tab \\ -- backslash \\ -- backslash \$ -- dollar sign \$ -- dollar sign \{, \), \[, \] \{, \), \[, \]

15 15 PHP Intro Parameter Passing to a Function $a = 10; $b = 20; echo add($a, $b). “\n”; echo $a. “\n”; echo $b. “\n”; function add($x, &$y) { $x++; $y++; return $x + $y; } 321021

16 16 PHP Intro Including a File An external file can be loaded with one of the following statements: The execution continues even when the file to be The execution continues even when the file to be loaded does not exist. loaded does not exist. The execution terminates when the file to be The execution terminates when the file to be loaded does not exist. loaded does not exist. and and A file is included only once even if it is requested A file is included only once even if it is requested multiple times. multiple times.

17 17 PHP Intro PHP Resources PHP Website - http://www.php.net PHP Website - http://www.php.nethttp://www.php.net PHP Manual – Getting Started: http://www.php.net/manual/en/getting-started.php PHP Manual – Getting Started: http://www.php.net/manual/en/getting-started.php http://www.php.net/manual/en/getting-started.php Hugh E. Williams and David Lane. Web Database Applications with PHP & MySQL. O'Reilly, ISBN 0-596-00041-3 (optional) Hugh E. Williams and David Lane. Web Database Applications with PHP & MySQL. O'Reilly, ISBN 0-596-00041-3 (optional) Other resources on the web Other resources on the web


Download ppt "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."

Similar presentations


Ads by Google