Presentation is loading. Please wait.

Presentation is loading. Please wait.

Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.

Similar presentations


Presentation on theme: "Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database."— Presentation transcript:

1

2 Website Development Introducing PHP

3 The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database

4 How PHP is written PHP is mixed with html PHP is kept between start and end tags The PHP interpreter, picks out the PHP code in the HTML It then interprets the code It then produces HTML This looks very messy The ideas are very simple though It is easier than CGI languages like Perl that have to write out the HTML

5 : Customer browser request service access page interpret set data present html return html get data databasescripting language web server How server side scripting works

6 First PHP instruction echo(“Mary had a little lamb”); Mary had a little lamb gets converted to you end statements with a semi-colon

7 Embedding in HTML ;... Code is placed between start and end tags:

8 ; echo("or this"); Test

9 you can escape into php like this, or simply like this, or this Results in the following HTML:

10 Variables Start with a $ Then a letter or underscore Then any number of letters, underscores or numbers Examples $customer $_1_of_the_many $go2work

11 PHP supports the following types: array floating-point numbers integer object string

12 ExampleNameResult $a + $bAdditionSum of $a and $b. $a - $bSubtractionDifference of $a and $b. $a * $bMultiplicationProduct of $a and $b. $a / $bDivisionQuotient of $a and $b. $a % $bModulusRemainder of $a divided by $b. Table 10-1. Arithmetic Operators

13 <?php $h = "Hello"; $w = "World"; echo($h); echo ($w); ?> Test

14 A useful property of strings Variables are expanded in strings $y = 2007; echo (“Year is $y”); echo (“Year is 2007”); is equivalent to

15 <?php $h = "Hello"; $w = "World"; $y = 2007; echo("This is another $h $w $y program"); ?> Test

16 A loop: for (exp1; exp2; exp3) statement; exp1 exp2 statement exp3 true false the statement can be a compound statement surrounded by { and }

17 <?php for ($i=1; $i<10; $i=$i+1) { echo("$i "); }; ?> Test

18 Auto-increment, auto-decrement $i++ $i-- add one to $i subtract one from $i

19 <?php for ($i=1; $i<15; $i++) { echo("$i "); }; ?> Test

20 Some clever stuff with loops You can include html in the loop statement for (exp1; exp2; exp3) { php code html code … };

21 A simple table HTML for creating a table

22 escape back to html Test

23 cell 1 cell 2 cell 3 cell 4 cell 5 Results in

24 Test

25 From here on I will introduce constructs as needed Look at the manual to find out more Links to the manual and other sources will be embedded in the slidesmanual Some useful references directly into the manual follow

26 Chapter 11. Control Structures if else elseif while do..while for foreach break continue switch

27 Table 10-3. Comparison Operators ExampleNameResult $a == $bEqualTrue if $a is equal to $b. $a != $bNot equalTrue if $a is not equal to $b. $a < $bLess thanTrue if $a is strictly less than $b. $a > $bGreater thanTrue if $a is strictly greater than $b. $a <= $bLess than or equal to True if $a is less than or equal to $b. $a >= $bGreater than or equal to True if $a is greater than or equal to $b.

28 PHP Array Example Test

29 PHP Form Handling

30 What this example does The page above contains two input fields and a submit button. When the user fills in this form and clicks on the submit button, the form data is sent to the "welcome.php" file. The "welcome.php" file looks contains these lines: Test

31 PHP File Handling The fopen() function is used to open files in PHP. The first parameter of this function contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened:

32 File Modes

33 Example The following example generates a message if the fopen() function is unable to open the specified file:

34 Reading a File Line by Line The example below reads a file line by line, until the end of file is reached: Test

35 Writing to the File So we could use the Post variable to write data entered via a form to a file. Then read it back line-by-line. Basis for a simple guestbook.

36 Summary PHP is a server side scripting language It is merged in with HTML The interpreter produces HTML It has a full range of variables and control structures We shall later look at functions and objects


Download ppt "Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database."

Similar presentations


Ads by Google