Web Technology- PHP - PowerPoint PPT Presentation

About This Presentation
Title:

Web Technology- PHP

Description:

Introduction of PHP – PowerPoint PPT presentation

Number of Views:100

less

Transcript and Presenter's Notes

Title: Web Technology- PHP


1
What is PHP?
  • PHP (recursive acronym for PHP Hypertext
    Preprocessor) is a widely used open source
    general purpose scripting language that is
    especially suited for web development and can be
    embedded into HTML.

2
Variables in PHP
  • Variables in PHP are represented by a dollar sign
    followed by the name of the variable. The
    variable name is case-sensitive.
  • A valid variable name starts with a letter or
    underscore, followed by any number of letters,
    numbers, or underscores. As a regular expression,
    it would be expressed as'a-zA-Z_\x7f-\xffa-zA
    -Z0-9_\x7f-\xff'
  • To assign values or expressions to variables, the
    standard assignment equal-sign operator ( ) is
    used

3

var "Bob" Var "Joe" // different variable Long_variable_numeric_name 47 4site 'not yet' // invalid starts with a number _4site 'not yet' // valid starts with an underscore

4
Variables and Types in PHP
Although variables are not declared to be type-specific in PHP, PHP still has a common set of data types Boolean, integer, float, string, array ,object, resource, NULL Determining the current type of a variable A series of type-testing functions exist to determine the current type of variables gettype(varname)returns type name, such as 'string is_int(), is_integer() ,is_long() ,is_null() ,is_numeric(), is_object() ,is_real(), is_string(), is_scalar() ,is_bool() empty(), isset() Special debugging / variable-display functions print_r() ,var_dump(), var_export()
5
Special Relationship Between Strings and
Variables
String constants can be defined in one of three common ways Inside Single Quotes 'One type of string Inside Double Quotes "Another type of string" Data inside Single-quoted strings are taken literally ie., everything is treated exactly as it is typed Data inside Double-quoted strings are treated in a special way in relationship to variable references and other standard formatting characters If a variable is referenced inside a double-quoted string, its value is automatically substituted.
6
Examples
  • var1 'ABC' var2 "Value is var1xyz" //
    "Value is "
  • var3 "Value is var1xyz" // "Value is
    ABCxyz"
  • var4 'Value is ' . var1 . 'xyz' // "Value is
    ABCxyz
  • var1 'This is a long variable that is
    continued onto multiple lines.'
  • var2 "This is a long variable with another
    variables defined inside it var1\n"

7
Using PHP in a Webpage
PHP source code is embedded in an HTML-based document, and is identified by special delimiting tags, lt?php   content   ?gt similar to Javascript and Java applets.
ltH2gtMy Webpagelt/H2gt This is my webpage. lt?php echo "This is written in PHP.\n" ?gt
8
Displaying Values
Values can be displayed (output) using three methodsecho,  print(), and printf()
9
echo
  • echo string arg1 , string argn...
  • echo outputs all values following it. It is not
    actually a function (it is a language construct)
    so you are not required to use parentheses with
    it.
  • echo can pass multiple string separated as ( , )
  • echo doesnt return any value
  • echo is faster then print

10
  • echo "This is a test\n"
  • var1 'Test string'
  • var2 75
  • echo "The value of var1 is var1\n"
  • echo "The value of var2 is var2\n"
  • echo "Multiple variables displayed var1
    var2\n"
  • echo "This is a value that is
  • written on multiple lines,
  • including variable var2 references. "
  • echo 'This',var2,'that' // "This75that"

11
Print()
  • print() is in some ways similar to echo, although
    it can be used as a function and could be
    included in more complicated expressions
  • using print can doesnt pass multiple argument
  • print always return 1
  • it is slower than echo

12
  • echo "This is a test\n"
  • var1 'Test string'
  • var2 75
  • print "The value of var1 is var1\n"
  • print ("The value of var2 is var2\n")
  • ret print "Hello World" // ret will equal 1

13
  • printf() is one member of a family of string
    formatting functions. It is based on the syntax
    of the sprintf() function.

var1 123.456 var2 255 var3 'text' printf ("ltpregtd 05d 5.2f '-10slt/pregt",var1,var2,var1,var3)
123 00255 123.46 text
14
String Concatenation Operator
  • To concatenate two string variables together, use
    the dot (.) operator
  • lt?php
  • string1"Hello World"
  • string2"1234"
  • echo string1 . " " . string2
  • ?gt
  • Hello World 1234

15
Using the strlen() function
  • The strlen() function is used to find the length
    of a string.
  • lt?php
  • echo strlen("Hello world!")
  • ?gt
  • 12

16
Using the strpos() function
  • The strpos() function is used to search for a
    string or character within a string.
  • If a match is found in the string, this function
    will return the position of the first match. If
    no
  • match is found, it will return FALSE.
  • Let's see if we can find the string "world" in
    our string
  • lt?php
  • echo strpos("Hello world!","world")
  • ?gt
  • 6

17
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com