Chapter 3 introduction to php
1 / 22

Chapter 3 Introduction to PHP - PowerPoint PPT Presentation

  • Uploaded on

Chapter 3 Introduction to PHP. By default, PHP documents end with the extension . php files ending with . htm or .html to also get parsed by the PHP processor

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about ' Chapter 3 Introduction to PHP' - hallam

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Incorporating php within html

  • By default, PHP documents end with the extension .php

  • files ending with .htmor .html to also get parsed by the PHP processor

  • To trigger the PHP commands, you need to learn a new tag. The first part is: <?phpthe closing part is encountered, which looks like this: ?>

Incorporating PHP Within HTML

Calling the php parser

Calling the PHP Parser

Using comments

  • There are two ways in which you can add comments

  • // This is a comment

  • after a line of code $x += 10; // Increment $x by 10

  • When you need multiple-line comments


    /* This is a section

    of multiline comments

    which will not be

    interpreted */


Using Comments

Basic syntax

  • Semicolons

    $x += 10;

    You must place a $ in front of all variables


    $mycounter = 1;

    $mystring = "Hello";

    $myarray = array("One", "Two", "Three");


Basic Syntax

Understanding variables

  • String variables $username = "Fred Smith";

    <?php // test1.php

    $username = "Fred Smith";

    echo $username;

    echo "<br />";

    $current_user = $username;

    echo $current_user;


Understanding Variables

Numeric variables

  • $count = 17; to store the number 17 in the variable $count

  • $count = 17.5; a floating-point number (containing a decimal point);

  • Arrays $team = array('Bill', 'Joe', 'Mike', 'Chris', 'Jim');

  • Two-dimensional arrays


    $oxo = array(array('x', '', 'o'),

    array('o', 'o', 'x'),

    array('x', 'o', '' ));


Numeric variables

Variable naming rules

  • four rules:

  • • Variable names must start with a letter of the alphabet or the _ (underscore) character.

  • • Variable names can contain only the characters: a-z, A-Z, 0-9, and _ (underscore).

  • • Variable names may not contain spaces. If a variable must comprise more than one word it should be separated with the _ (underscore) character. (e.g., $user_name).

  • • Variable names are case-sensitive. The variable $High_Score is not the same as the variable $high_score.

Variable naming rules



Arithmetic operators
Arithmetic operators logical commands such

Assignment operators
Assignment operators logical commands such

Comparison operators
Comparison operators logical commands such

Logical operators
Logical operators logical commands such

Variable assignment

  • The syntax to assign a value to a variable is always logical commands such variable = value. Or, to reassign the value to another variable, it is other variable = variable.

  • Variable incrementing and decrementing

  • String concatenation uses the period (.) to append one string of characters to another. The simplest way to do this is as follows:

    echo "You have " . $msgs . " messages.";

Variable Assignment

Multiple line commands

Multiple-Line Commands

Variable typing

  • V logical commands such ariables do not have to be declared before they are used, and that PHP always converts variables to the type required by their context when they are accessed.

Variable Typing


  • Constants logical commands such are similar to variables, holding information to be accessed later, except that they are what they sound like—constant


E cho and print commands

  • echo cannot be used as part of a logical commands such more complex expression, whereas print can

    $b ? print "TRUE" : print "FALSE";

  • The question mark is simply a way of interrogating whether variable $b is true or false. Whichever command is on the left of the following colon is executed if $b is true, whereas the command to the right is executed if $b is false

Echo and print Commands


  • A simple function logical commands such declaration


    function longdate($timestamp)


    return date("l F jS Y", $timestamp);




A function using a static variable

< keyword global?php

function test()


static $count = 0;

echo $count;




A function using a static variable

Php s superglobal variables
PHP’s keyword globalsuperglobal variables