Download presentation
Presentation is loading. Please wait.
1
PHP: Hypertext Processor Fred Durao fred@cs.aau.dk
2
Origins and Uses of PHP - Origins - Rasmus Lerdorf - 1994 - Developed to allow him to track visitors to his Web site - PHP is an open-source product - PHP was originally an acronym for Personal Home Page, but later it became PHP: Hypertext Preprocessor - PHP is used for form handling, file processing, and database access PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
3
Overview of PHP - PHP is a server-side scripting language whose scripts are embedded in HTML documents - Similar to JavaScript, but on the server side - PHP syntax is similar to that of JavaScript For a browser read and interpret the PHP commands, the file must be have an extension.PHP EXAMPLE - before myPage.html - now myPage.php More at http://www.w3schools.com/php/php_intro.asp
4
General Syntactic Characteristics - PHP code can be specified in an HTML document internally or externally: Internally: <?php.......php code goes here......... ?> Externally: include ("myScript.inc") - the file can have both PHP and HTML - Comments - three different kinds //... #... /*... */ - Output from a PHP script is HTML that is sent to the browser. - PHP code is placed in the body of an HTML document
5
A little bit of “Programming” -It is the process of designing, writing, testing, debugging, and maintaining the source code of computer programs. - This source code is written in a programming language. - The code may be a modification of an existing source or something completely new. - The purpose of programming is to create a program that exhibits a certain desired behavior (customization).
6
A little bit of “Programming” (continue) -The details look different in different languages, but a few basic instructions appear in just about every language: - input: Get data from the keyboard, a file, or some other device. - output: Display data on the screen or send data to a file or other device. - arithmetic: Perform basic arithmetical operations like addition and multiplication. - conditional execution: Check for certain conditions and execute the appropriate sequence of statements. - repetition: Perform some action repeatedly, usually with some variation. THE program languages such as PHP, JAVA, C, JAVASCRIPT,... Implement these instructions though commands. Usually each program language has its own syntax.
7
PHP –> VARIABLE Variables are used for storing values, like text strings, numbers or arrays. When a variable is declared, it can be used over and over again in your script. All variables in PHP start with a $ sign symbol. Example $var_name = value; http://en.wikipedia.org/wiki/Variable_%28programming%29 http://www.w3schools.com/php/php_variables.asp
8
PHP –> Control Statements - Relational operators - same as JavaScript, (including === and !== ) - Boolean operators – “OR” and “AND” - Selection statements - if, if - else, elseif - HTML can be intermingled with PHP script <?php $a = 7; $b = 7; if ($a == $b) { $a = 3 * $a; } ?>
9
User-Defined Functions - Syntactic form: function function_name ( formal_parameters ) { … } - General Characteristics - Functions need not be defined before they are called - The return function is used to return a value; - If there is no return, there is no returned value EXAMPLE function set_max(&$max, $first, $second) { if ($first >= $second) $max = $first; else $max = $second; }
10
PHP –> COMMANDS - > ECHO PHP has a number of predefined functions ready use. Echo () PHP Function - is used to output the given argument. <?php Echo "Hello"; //Outputs a string Echo $variable; //Outputs a variable Echo "Multiple things ". $on. " one line"; //Outputs a string, then a variable, then a string. All are separated with a [.] period ?>
11
PHP –> COMMANDS -> MAIL PHP has a number of predefined functions ready use. Mail () PHP Function - is used to send an email. mail ($to, $subject, $message, $headers) // headers are optional <?php $to = 'nobody@example.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com'. "\r\n". 'Reply-To: webmaster@example.com'. "\r\n". mail($to, $subject, $message, $headers); ?>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.