5-php

Upload: lan-lu

Post on 10-Jan-2016

213 views

Category:

Documents


0 download

DESCRIPTION

PhP

TRANSCRIPT

Slide 1

Server-side script: PhPHieu Dinh VoWeb Technology IntroductionWeb Client - Server2

1.2. Execute3.Server-side ScriptsScripts (programs) developed to run at server side (result will be sent to clients)Examples: JSP, ASP, Python, Perl, PhP. etc

3PhPPHP is an open-source technologyPHP is platform independentPHP also supports many databasesFirst PhP Script(example)5PhP SyntaxWhitespace insensitiveStatements ended by semicolonComments/*.*/ for multiple lines// or # for a line

6PhP SyntaxVariablesAll variables in PHP are denoted with a leading dollar sign ($).Variables can, but do not need, to be declared before assignmentVariables used before they are assigned have default values.

7TypesIntegers are whole numbers, without a decimal point, like 495.Doubles are floating-point numbers, like 3.14159 or 49.0.Booleans have only two possible values: TRUE and FALSE.NULL is a special type that only has one value: NULL.Strings are sequences of characters, like PHP 4.0 supports string operations.Arrays are named and indexed collections of other values.Objects are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.Resources are special variables that hold references to resources external to PHP (such as database connections).8Outputechoprint9Control StructuresSimilar to JavaScriptif, if elseforwhileswitch case 10FunctionsSimilar to JavaScript

11String $my_string=This is a string;$another_string=This is another string;

$statement = everything I say;$question_1 = Do you have to take statement so literally?\n
;$question_2 = Do you have to take $statement so literally?\n
;echo $question_1;echo $question_2;12Do you have to take everything I say so literally?Do you have to take $statement so literally?\nString$sport = volleyball;$plan1 = I will play $sport in the summertime;$plan2 = I will play {$sport} in the summertime;

13String index$str=abcde$str[0] a$str[3] d14Concatenation$my_two_cents = I want to give you a piece of my mind ;$third_cent = And another thing;print($my_two_cents . ... . $third_cent);15I want to give you a piece of my mind ... And another thingString Functions$short_string = This string has 29 characters;strlen($short_string)strpos($short_string,9)strrpos($short_string,a)To compare: ==strstr($short_string,has)substr($short_string,5)substr($short_string,5,6)

16Forms17

Original string:

Forms are means for convey data from users (via Web browser) to serverPOST vs. GETGET: query data sent as a part of URLPOST: data is hidden18Obtaining Data19

HTML & PhPTwo ways to use HTML in PhPUse echo or print to produce HTML tagsPut HTML tags outside of segment20

21