1 / 16

Advance web Programming Chapter 1: Introduction

Advance web Programming Chapter 1: Introduction. Dr. Mogeeb A. A. Mosleh E-mail : MogeebMosleh@Gmail.com Notes : faculty web site – ELS Lab Room : MM lab. What is PHP?. PHP is an acronym for "PHP Hypertext Preprocessor" PHP is a widely-used, open source scripting language

ember
Download Presentation

Advance web Programming Chapter 1: Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advance web Programming Chapter 1: Introduction Dr. Mogeeb A. A. Mosleh E-mail : MogeebMosleh@Gmail.com Notes : faculty web site – ELS Lab Room : MM lab

  2. What is PHP? • PHP is an acronym for "PHP Hypertext Preprocessor" • PHP is a widely-used, open source scripting language • PHP scripts are executed on the server • PHP costs nothing, it is free to download and use

  3. What is a PHP File? • PHP files can contain text, HTML, CSS, JavaScript, and PHP code • PHP code are executed on the server, and the result is returned to the browser as plain HTML • PHP files have extension ".php"

  4. What Can PHP Do? • PHP can generate dynamic page content • PHP can create, open, read, write, delete, and close files on the server • PHP can collect form data • PHP can send and receive cookies • PHP can add, delete, modify data in your database • PHP can restrict users to access some pages on your website • PHP can encrypt data

  5. Why PHP? • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) • PHP is compatible with almost all servers used today (Apache, IIS, etc.) • PHP supports a wide range of databases • PHP is free. Download it from the official PHP resource: www.php.net • PHP is easy to learn and runs efficiently on the server side

  6. Basic PHP Syntax • A PHP script can be placed anywhere in the document. • A PHP script starts with <?php and ends with ?>: • <?php// PHP code goes here?> • PHP Case Sensitivity • In PHP, all user-defined functions, classes, and keywords (e.g. if, else, while, echo, etc.) are NOT case-sensitive. • However; in PHP, all variables are case-sensitive. • Ex.

  7. PHP Variables • As with algebra, PHP variables can be used to hold values (x=5) or expressions (z=x+y). • A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). • Rules for PHP variables: • A variable starts with the $ sign, followed by the name of the variable • A variable name must start with a letter or the underscore character • A variable name cannot start with a number • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) • Variable names are case sensitive ($y and $Y are two different variables) Variables are "containers" for storing information: • <?php$x=5;$y=6;$z=$x+$y;echo $z;?>

  8. PHP Variables Scope • In PHP, variables can be declared anywhere in the script. • The scope of a variable is the part of the script where the variable can be referenced/used. • PHP has three different variable scopes: • local • global • static

  9. PHP echo and print Statements • There are some differences between echo and print: • echo - can output one or more strings • print - can only output one string, and returns always 1 • echo and print are a language construct, and can be used with or without parentheses: echo or echo().

  10. PHP Data Types • PHP Strings • A string is a sequence of characters, like "Hello world!". • PHP Integers • An integer is a number without decimals. Rules for integers: • An integer must have at least one digit (0-9) • An integer cannot contain comma or blanks • An integer must not have a decimal point • An integer can be either positive or negative • Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based - prefixed with 0x) or octal (8-based - prefixed with 0). • PHP Floating Point Numbers • A floating point number is a number with a decimal point or a number in exponential form. • PHP Booleans • Booleans can be either TRUE or FALSE. • PHP Arrays • An array stores multiple values in one single variable.

  11. PHP String Functions • The PHP strlen() function: echo strlen("Hello world!"); • The PHP strpos() function: echo strpos("Hello world!","world"); • Complete PHP String Reference: library http://www.w3schools.com/php/php_ref_string.asp. • Different between • Echo “ “ & echo ‘ ‘;

  12. PHP if...else...elseif Statements • In PHP we have the following conditional statements: • if statement - executes some code only if a specified condition is true • if...else statement - executes some code if a condition is true and another code if the condition is false • if...elseif....else statement - selects one of several blocks of code to be executed • switch statement - selects one of many blocks of code to be executed

  13. PHP Loops • In PHP, we have the following looping statements: • while - loops through a block of code as long as the specified condition is true • do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true • for - loops through a block of code a specified number of times • foreach- loops through a block of code for each element in an array

  14. PHP Arrays • In PHP, the array() function is used to create an array: • In PHP, there are three types of arrays: • Indexed arrays - Arrays with numeric index • Associative arrays - Arrays with named keys • Multidimensional arrays - Arrays containing one or more arrays. • Complete PHP Array Reference http://www.w3schools.com/php/php_ref_array.asp

  15. PHP Sorting Arrays • sort() - sort arrays in ascending order • rsort() - sort arrays in descending order • asort() - sort associative arrays in ascending order, according to the value • ksort() - sort associative arrays in ascending order, according to the key • arsort() - sort associative arrays in descending order, according to the value • krsort() - sort associative arrays in descending order, according to the key

  16. PHP Global Variables - Supergloba • The PHP superglobal variables are: • $GLOBALS • $_SERVER • $_REQUEST • $_POST • $_GET • $_FILES • $_ENV • $_COOKIE • $_SESSION

More Related