Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP: Hypertext Preprocessor

Similar presentations


Presentation on theme: "PHP: Hypertext Preprocessor"— Presentation transcript:

1 PHP: Hypertext Preprocessor

2 PHP An HTML embedded scripting language
JSP, ASP (executes on webserver) VBScript, Javascript (executes in browser) PHP is (normally) used on a webserver Output from a php script is usually HTML Aim is to allow web developers to write dynamically generated pages quickly Much syntax borrowed from C, Java and Perl “Glue” between lots of other programs Database friendly Client/Server application friendly Widely used open source scripting language Started in 1995, under continual development

3 PHP and HTML PHP is usually part of an HTML page Special HTML tag
<?php php program ?> Webserver sends html file to php interpreter Interpreter looks for <?php … ?> tag and interprets code Output (may be html) replaces php tags Other html passes through unchanged Interpreter sends output back to webserver Page sent to remote browser

4 Basic features All the usual programming language features (plus some…) Instruction separation As in C or PERL, new lines are not important. instructions end with a semicolon (;) character Comments C (/* … */) C++ (//) Unix Shell (#) Variables Start with a dollar ($) symbol Programmer needn’t specify datatype Some special variables from outside PHP

5 More features Arrays Functions Control Structures
Actually an “ordered map” “map” from a key to a value Use square brackets [] to access arrays Value can also be an array Some predefined arrays for getting information from webserver Functions Hundreds of built-in functions Control Structures Conditional Statements If, else, elseif Loops while, do-while, for, foreach, switch, break, continue

6 Working with forms Reason PHP was invented! HTML forms
Can use HTTP ‘POST’ or ‘GET’ methods to send data to webserver PHP predefined variables $_GET array $_POST array Elements are named as in the HTML form

7 Sessions Each request from a browser is independent
Need to keep track of which request comes from which browser PHP makes this simple with a $_SESSION array variable – any data stored here will be maintained for the browser ‘session’

8 Local filesystem Can read and write to other files on the webserver
Access files using a handle Lots of functions to access files fopen – open file and get a handle ffeof – test for end of file fgets – read a line from a file fwrite – write a line to a file fclose – close a file flock – test for and lock, or unlock, a file Writing to a file Must lock file first Shouldn’t allow user to interrupt script while we write our data [ignore_user_abort(true);]


Download ppt "PHP: Hypertext Preprocessor"

Similar presentations


Ads by Google