Presentation is loading. Please wait.

Presentation is loading. Please wait.

©John Samuel 2008 Introduction to PHP. ©John Samuel 2008 Objectives At the end of this class the student will be able to; Create and run a simple php.

Similar presentations


Presentation on theme: "©John Samuel 2008 Introduction to PHP. ©John Samuel 2008 Objectives At the end of this class the student will be able to; Create and run a simple php."— Presentation transcript:

1 ©John Samuel 2008 Introduction to PHP

2 ©John Samuel 2008 Objectives At the end of this class the student will be able to; Create and run a simple php program using their Zenit account. Explain the basic way in with PHP works. Explain how to add PHP code to an XHTML document.

3 ©John Samuel 2008 Objectives At the end of this class the student will be able to; Write and execute simple PHP programs using the following language features: Comments Variables Arrays and array functions Use php to create simple dynamic XHTML programs.

4 ©John Samuel 2008 Php installation You can run php programs on your Zenit accounts. If you want your own development environment for php, you will need to install a web server first (Apache recommended) and then php. To duplicate the environment on Zenit you will also need to install MySql. Follow the install instructions included with each download carefully.

5 ©John Samuel 2008 Apache installation If you already have another web server installed, (e.g. IIS or PWS) you will need to assign a different port to Apache, by editing httpd.conf.

6 ©John Samuel 2008 Configuration Configuration of php can be done by editing the php.ini file. Read the php documentation and the internal comment in the ini file to make sure that you know what you are changing. http://www.php.net/manual/en/configuration.directives.php

7 ©John Samuel 2008 Configuration asp-style tags are not enabled on zenit. Make sure that any assignment code you write at home will run on zenit. If you wish, you can change your php.ini file so that asp/jsp stype tags are also accepted, i.e. change the following line ; Allow ASP-style tags. asp_tags = Off To ; Allow ASP-style tags. asp_tags = On

8 ©John Samuel 2008 Configuration Allowing asp-style and short open tags on zenit: Create a file named.htaccess in the directory that has your php code. Add the following content: php_flag asp_tags on php_flag short_open_tag on

9 ©John Samuel 2008 Configuration You can test PHP and learn about its settings by using the function phpinfo().

10 ©John Samuel 2008 PHP Stands for Personal HomePage Created by Rasmus Lerdorf for his own use. Latest version 5.x Part of “LAMP” technologies (www.onlamp.com)

11 ©John Samuel 2008 PHP It is extremely easy to learn. Syntax is a mix of C and Perl. PHP is a function-based language. There are thousands of PHP functions for just about any imaginable purpose.

12 ©John Samuel 2008 PHP Start with HTML and add specially marked sections of code. Code is executed, any changes or additions are made to the HTML code, and it is returned to the browser/user agent for ‘display’.

13 ©John Samuel 2008 PHP Any XHTML page can be turned into a PHP page simply by changing the extension to.php

14 ©John Samuel 2008 PHP tags There are 3 (4) ways to mark PHP code inside a document. Note ; at end of each line. Multiple lines allowed between start and end tags. __ML can be included in PHP print statements.

15 ©John Samuel 2008 PHP tags There are 2 shortcuts for including literal or variable data without a print statement, (if short tags enabled) (if asp tags enabled) E.g. Note, no ; after data

16 ©John Samuel 2008 PHP tags When developing PHP code that may be used by others (modules), it is recommended that you use the formal tags since the other forms are configurable and may not be supported on the user’s system.

17 ©John Samuel 2008 Comments Inside the PHP tags, the following comment styles are allowed. Outside the PHP tags, comments must follow the style of the ML (usually ). Single line PHP comments: // # Multiple line PHP comments: /* */

18 ©John Samuel 2008 Comments Note that PHP comment markers only apply inside PHP tags, e.g. this part gets printed

19 ©John Samuel 2008 Variable types There are six types: boolean integer string float objects (beyond scope of course) array Variable capacity is system dependent.

20 ©John Samuel 2008 Casting You can cast in the C style, or use the function settype(). See variables.php

21 ©John Samuel 2008 Variable functions There are many useful functions for working with variables. gettype() returns the type of the variable. There is a boolean function for each type, e.g. is_int($x) returns true if $x is an integer, etc. Can use var_dump() to print details about a value. See variables.php See http://ca3.php.net/variables for a list of variable functions.http://ca3.php.net/variables

22 ©John Samuel 2008 Arrays Can be multidimensional. Can be indexed or associative. Three important keywords are: array list range See arrays.php

23 ©John Samuel 2008 Array functions There are many useful array functions. See arrayfunctions.php See http://www.php.net/manual/en/ref.array.php for a complete list. http://www.php.net/manual/en/ref.array.php

24 ©John Samuel 2008 “” vs. ‘’ Variables and special characters inside “” are interpolated, but ‘’ are not. Same as in Perl.

25 ©John Samuel 2008 Review What are the PHP comment styles? How does PHP treat variables? What are PHP’s variable types?


Download ppt "©John Samuel 2008 Introduction to PHP. ©John Samuel 2008 Objectives At the end of this class the student will be able to; Create and run a simple php."

Similar presentations


Ads by Google