PHP Part I - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

PHP Part I

Description:

Comments in PHP. Data Types. Variables. CECS 201. Database Applications and Information ... echo 'One Final Test'; # This is shell-style style comment. CECS 201 ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 18
Provided by: diglib1Ce
Category:
Tags: php | comment | part

less

Transcript and Presenter's Notes

Title: PHP Part I


1
PHP Part I
  • PHP Filter Processed
  • PHP Code blocks, scriplets
  • Comments in PHP
  • Data Types
  • Variables

2
PHP Parsing
  • When PHP parses a file, it simply passes the text
    of the file through until it encounters one of
    the special tags which tell it to start
    interpreting the text as PHP code. The parser
    then executes all the code it finds, up until it
    runs into a PHP closing tag, which tells the
    parser to just start passing the text through
    again. This is the mechanism which allows you to
    embed PHP code inside HTML everything outside
    the PHP tags is left alone, while everything
    inside is parsed as code.

3
Blocks of PHP code
  • 1.  lt?php echo("if you want to serve XHTML or XML
    documents, do like this\n") ?gt
  • 2.  lt? echo ("this is the simplest, an SGML
    processing instruction\n") ?gt    lt? expression
    ?gt This is a shortcut for "lt? echo expression
    ?gt"  
  • 3.  ltscript language"php"gt       echo ("some
    editors (like FrontPage) don't             like
    processing instructions")   lt/scriptgt
  • 4.  lt echo ("You may optionally use
    ASP/JSP-style tags") gt   lt variable This
    is a shortcut for "lt echo . . ." gt

4
PHP Comments
  • lt?php
  • echo "This is a test" // This is a one-line c
    style comment
  •    / This is a multi line comment       yet
    another line of comment /
  • echo "This is yet another test"
  • echo "One Final Test" This is shell-style
    style comment
  • ?gt

5
Data Types in PHP
  • PHP supports eight primitive types.
  • Four scalar types
  • boolean
  • integer
  • float (floating-point number, aka 'double')
  • string
  • Two compound types
  • array
  • object
  • And finally two special types
  • resource
  • NULL

6
Variables
  • Variables in PHP are represented by a dollar sign
    followed by the name of the variable.
  • The variable name is case-sensitive
  • e.g.
  • myVar, query

7
Arrays
  • A PHP array is an ordered map
  • Can be used as array
  • List
  • Vector
  • Hashtable
  • array(keygtvalue, )
  • Key can be integer or string

8
Referencing Array Elements
  • Reference by number
  • arr12
  • Gives value mapped using integer 12, not
    necessarily the 12th (or 13th) element
  • arrtwelve
  • Gives value mapped by the string twelve

9
Specifying values without key
  • arr1 array(val1, val2, val3)
  • 0gtval1, 1gtval2, 2gtval3
  • arr2 array(7gtval1, val2, val3)
  • 7gtval1, 8gtval2, 9gtval3
  • arr2 val4
  • 7gtval1, 8gtval2, 9gtval3, 10gtval4

10
Removing Values from Array
  • unset(arr0)
  • Removes the 0 index element
  • unset(arr)
  • Removes the array

11
Objects
  • class classOne
  • function f1()
  • echo classOne.f1()
  • obj1 new classOne
  • obj1-gtf1()

12
Resource Data Type
  • A resource is a special variable, holding a
    reference to an external resource.
  • Resources are created and used by special
    functions
  • Due to the reference-counting system introduced
    with PHP 4's Zend Engine, it is automatically
    detected when a resource is no longer referred to
    (just like Java).

13
Common Resources
  • ftp an FTP Stream
  • java
  • mssql link - to a MS SQL Server database
  • mysql link - to a MySQL Server database
  • oci8 connection to Oracle database
  • odbc link to ODBC database
  • oracle link to Oracle Database

14
NULL Values
  • For variables that have no Value
  • it has been assigned the constant NULL. var
    NULL
  • it has not been set to any value yet.
  • it has been unset().

15
Operators
  • Most standard programming language operators,
    some additional ones
  • identical, i.e. equal and same type
  • ltgt, ! both are not equal comparisons
  • ! not identical
  • and,or,xor, !, , logical operators
  • . . are two string concatenation operators

16
Array operators
  • union operator
  • equality test, same elements
  • identical, same elements and same order
  • !, ltgt not equal
  • ! not identical

17
To do
  • Find and read a web tutorial on basic HTML (web
    pages)
  • Understand common HTML elements
  • HTML, HEAD and BODY
  • Headings, Links
  • Tables, Forms
  • FrameSets
Write a Comment
User Comments (0)
About PowerShow.com