Professional Documents
Culture Documents
Phpweek 1 PDF
Phpweek 1 PDF
PHP
• PHP: Hypertext Preprocessor
• A powerful tool for making dynamic and
interactive Web pages.
• PHP is a server-side scripting language, like
ASP, JSP, CGI, Perl
• open source software
• free to download and use
• runs on different platforms (Windows, Linux,
Unix, etc.)
• AppServ.exe provides easy
installation
(http://www.appservnetwork.com/)
• Directory structure after
installation
• Create first.php file under
www folder
• To run, Open browser
• Writwe localhost/first.php
• A PHP scripting block always starts with <?php
and ends with ?>.
• A PHP scripting block can be placed anywhere
in the document.
• The file must have a .php extension.
• If the file has a .html extension, the PHP code
will not be executed.
Single-line & Multi-line Comment
• Similar to C,
C++,Java, C#
Variables
• A variable is used to store information.
• Variables start with a $ sign (attention!)
• If you forget to use $ sign at the beginning of the variable, your program
will not work
• In a strongly typed programming language like C, you have to declare
(define) the type and name of the variable before using it.
• In PHP, the variable is declared automatically when you use it (implicit).
• In PHP, a variable does not need to be declared before adding a value to it.
• PHP automatically converts the variable to the correct data type,
depending on its value.
• 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, 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 an
underscore ($total_students), or with capitalization ($ totalStudents)
PHP Operators
• Arithmetic:
+, -, *, /, %, ++, --
• Assignment
=, +=, -=, *=, .=
• Comparison
==, !=, >, <, >=, <=
• Logical
&&, ||, !
• String
. dot sign for concatenation
Concatenation operator converts all parameters to string
Conditional Statements
• If...Else Statements
• Switch Statement
Expression can be any value even string!
LOOP STATEMENTS
• For statement
• While Statement
• Do...while Statement
FORM PROCESSING
Output
• Change method GET as POST
POST AND GET METHODS
• Two methods that browsers send form data to
php file
Data Flow: GET method
1) requests form.html Server
Client 139.179.10.12
GET /form.html HTTP/1.0
www.bilkent.edu.tr
2) Respond the request as
HTTP/1.0 200 OK form.html
Date: Fri, 30 Dec 2012 12:45:33 total.php
Content-Type:text/html
<html>
<form ... > ... </form>
...
</html>