7/30/2019 PHP_part_1
1/14
2008 Pearson Education, Inc. All rights reserved.
1
23
PHP
http://www.uml.org/7/30/2019 PHP_part_1
2/14
2008 Pearson Education, Inc. All rights reserved.
2
23.1 Introduction
23.2 PHP Basics
23.3 String Processing and Regular Expressions23.3.1 Comparing Strings
23.3.2 Regular Expressions
23.4 Form Processing and Business Logic
23.5 Connecting to a Database
23.6 Using Cookies
23.7 Dynamic Content
23.8 Operator Precedence Chart
23.9 Wrap-Up
23.10 Web Resources
http://www.uml.org/7/30/2019 PHP_part_1
3/14
2008 Pearson Education, Inc. All rights reserved.
3
23.1 Introduction
PHP, or PHP: Hypertext Preprocessor, hasbecome one of the most popular server-side
scripting languages for creating dynamic web
pages.
PHP is open source and platform independent
implementations exist for all major UNIX, Linux,
Mac and Windows operating systems. PHP also
supports a large number of databases.
http://www.uml.org/7/30/2019 PHP_part_1
4/14
2008 Pearson Education, Inc. All rights reserved.
4
23.2 PHP Basics
The power of the web resides not only in serving content to users, butalso in responding to requests from users and generating web pageswith dynamic content.
PHP code is embedded directly into XHTML documents, thoughthese script segments are interpreted by a server before beingdelivered to the client.
PHP script file names end with .
In PHP, code is inserted between the scripting delimiters and. PHP code can be placed anywhere in XHTML markup, as long as
the code is enclosed in these delimiters.
http://www.uml.org/7/30/2019 PHP_part_1
5/14
2008 Pearson Education, Inc. All rights reserved.
5
23.2 PHP Basics (Cont.)
Variables are preceded by a and are created the first time they areencountered.
PHP statements terminate with a semicolon ( ).
Single-line comments which begin with two forward slashes ( ) or apound sign ( ). Text to the right of the delimiter is ignored by theinterpreter. Multiline comments begin with delimiter and end withdelimiter .
When a variable is encountered inside a double-quoted ( ) string,PHP interpolates the variable. In other words, PHP inserts thevariables value where the variable name appears in the string.
All operations requiring PHP interpolation execute on the server
before the XHTML document is sent to the client.
http://www.uml.org/7/30/2019 PHP_part_1
6/14
2008 Pearson Education,Inc. All rights reserved.
61
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Outline
Delimiters
enclosing PHP
script
Declares and
initializes a PHP
variable
Interpolates the variable
so that its value will be
output to the XHTML
document
http://www.uml.org/7/30/2019 PHP_part_1
7/14 2008 Pearson Education, Inc. All rights reserved.
7
23.2 PHP Basics (Cont.)
Type conversions can be performed using function. This function takes two argumentsa variablewhose type is to be changed and the variables new type.
Function returns the current type of itsargument.
Calling function can result in loss of data. Forexample, doubles are truncated when they are convertedto integers.
When converting from a string to a number, PHP uses thevalue of the number that appears at the beginning of the
string. If no number appears at the beginning, the stringevaluates to .
The concatenation operator ( ) combines multiple strings.
http://www.uml.org/7/30/2019 PHP_part_1
8/14
2008 Pearson Education,Inc. All rights reserved.
81
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Outline
(1 of 3)
Automatically declares a string
Automatically declares a double
Automatically declares an integer
Outputs the type of$testString
23
http://www.uml.org/7/30/2019 PHP_part_1
9/14
2008 Pearson Education,Inc. All rights reserved.
923
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Outline
(2 of 3)
Modifies $testString
to be a double
Modifies $testString
to be an integerModifies $testString
to be a string
43
http://www.uml.org/7/30/2019 PHP_part_1
10/14
2008 Pearson Education,Inc. All rights reserved.
1043
44
45
46
47
48
49
50
51
52
53
54
Outline
(3 of 3)
Temporarily casts
$data as a double
and an integer
Concatenation
http://www.uml.org/7/30/2019 PHP_part_1
11/14 2008 Pearson Education, Inc. All rights reserved.
11
23.2 PHP Basics (Cont.)
Function creates a named constant. It takes twoargumentsthe name and value of the constant. An
optional third argument accepts a boolean value that
specifies whether the constant is case insensitive
constants are case sensitive by default.
Uninitialized variables have the value , which has
different values, depending on its context. In a numeric
context, it evaluates to . In a string context, it evaluates
to an empty string ( ).
1
http://www.uml.org/7/30/2019 PHP_part_1
12/14
2008 Pearson Education,Inc. All rights reserved.
121
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Outline
(1 of 3)
Creates the namedconstant VALUE with a
value of 5
Equivalent to $a = $a * 2
1328
http://www.uml.org/7/30/2019 PHP_part_1
13/14
2008 Pearson Education,Inc. All rights reserved.
1328
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Outline
(2 of 3)Uses a comparison operatorwith a variable and an integer
Uninitialized variable$num evaluates to 0
1453
http://www.uml.org/7/30/2019 PHP_part_1
14/14
2008 Pearson Education,Inc. All rights reserved.
1453
54
55
56
57
58
59
60
61
62
Outline
(3 of 3)
$str is converted to an
integer for this operation
http://www.uml.org/Recommended