! http://natahaus.ru/
This file was downloaded from natahaus.ru portal
**********************************************************
http://www.natahaus.ru/
,
.
!
,
.
,
.
.
.
.
.
.
,
, ,
e-mail -
.
PHP 5
""
-
2005
32.973.26-018.2.75
15
681.3.07
""
. ..
. . ..
"" :
info@dialektika.com, http://www.dialektika.com
115419, , / 783; 03150, , / 152
,
15 5 "".: . . .: "", 2005. 320 .: .
. . .
ISBN 5-8459-0851-5 (.)
Web- 5.
Web,
, . .
.
5 Web >
, Web- Apache !.
, , 1 Web.
32.973.26-018.2/5
.
, ,
, JOHN
WJLEY&Sons, Inc.
Copyright 2005 by Dialektika Computer Publishing.
Original English language edition Copyright 2004 by Wiley Publishing, Inc.
Allrightsreserved including therightof reproduction in whole or in part in any form. This translation published
by arrangement with Wiley Publishing, Inc.
For Dummies and Dummies Man are trademarks under exclusive license to Wiley Publishing, Inc. Used by
permission.
ISBN 5-8459-0851-5 (.)
ISBN 0-7645-4166-8 (.)
- "", 2005
Wiley Publishing, Inc., 2004
16
I.
19
1.
21
2.
29
3.
43
II.
55
4.
57
5.
72
6.
89
III.
7.
113
8.
134
9. -
148
IV. -
165
10. Web-
167
11. Web-
188
12.
207
13.
231
14.
250
V.
263
15. ,
265
16. Web-
270
VI.
273
275
293
310
16
I.
19
1.
Web-
Web
5
:>
:
2.
Web-
Web-
Web-
-
29
3.
HTML-
Web
43
43
44
45
46
48
49
:0
:>1
:>2
L6
16
17
17
18
:>2
:>2
:>
:4
:>4
:
:5
:>
27
21
29
:
:
34
:i6
:\9
:\9
40
40
41
II.
55
4.
Web-
5.
timestamp
6.
echo
list
57
57
58
58
59
60
61
62
63
63
63
64
66
66
67
67
68
69
70
72
72
72
73
74
74
76
78
79
79
80
81
81
82
85
86
87
89
89
89
91
92
92
93
94
95
95
foreach
( )
( )
,
$_SERVER $_ENV
$argv $argc
!6
96
(
>7
98
98
'19
11)0
101
102
102
103
103
104
105
105
106
107
107
108
109
III.
7.
if
switch
for
while
dcwhile
8.
()
1 [3
113
114
115
116
1L6
119
1: > 1
121
124
125
126
129
1:
1)1
1.32
134
155
135
136
137
138
138
140
141
9. -
-
- 5
-
$this
145
146
147
148
148
149
149
149
150
151
151
151
152
152
152
152
153
154
154
154
155
157
158
161
161
162
IV. -
165
10. Web-
Web-
, Web-
Web-
Web-
HTML-
Web-
11. Web-
Web-
Web-
URL-
167
167
168
168
169
169
170
170
171
177
179
186
188
188
188
189
189
190
191
191
cookie
HTML-
JavaScript
JavaScript
JavaScript
12.
...
SQLite
193
194
195
200
200
200
201
202
202
205
205
206
207
208
209
210
211
213
216
216
2]8
220
221
225
227
229
13.
,
system()
()
passthru()
FTP
FTP
FTP
FTP
231
231
2 32
233
2 34
236
238
239
239
2 40
240
241
241
2 42
2 42
243
244
245
246
246
14.
250
250
251
10
PEAR
PEAR
PEAR
PEAR
PEAR
254
255
256
258
259
V.
263
15. ,
,
265
265
266
266
266
266
267
267
268
268
269
16. Web-
Web-
Zend
Web-pecypc Builder
Web- Black Beans
PHP
Web-pecypc PHP Dev Center
Web- PHPMac .com
Web-pecypc SourceForge.net
Web-
Web-
270
270
270
270
271
271
271
271
271
271
271
272
272
VI.
273
.
Unix/Linux
Unix/Linux
Unix/Linux
Apache
Unix/Linux/Mac
Apache Unix/Linux/Mac
Windows
CGI
Web- Windows
275
275
276
276
278
280
280
281
283
284
286
287
289
290
11
.
HTTP
293
2* '3
297
297
3(12
3(12
3(14
305
308
3.0
12
OJ atftftofie
(Janet Valade) ,
Linux Web-.
. Web Web- ,
.
, ,
,
, .
/
, .
'BUatoqafiHOCfHU
.
, , ,
. ,
,
.
.
/
, , .
, ,
.
, .
.
, Web- .
, , ,
, .
, ,
.
. :
E-mail:
info@dialektika.com
WWW:
http://www.dialektika.com
:
:
115419, , / 783
03150, , / 152
, , . ,
, .
. .
, Web-
. .
Web-.
, . ,
. , .
.
, ,
.
.
.
*
:
. .
, . (
.)
. , .
. ,
Web, ,
. ,
, . , ,
.
, ,
. . , . \
, ,
.
, ,
. :
, ,
.
, . ,
echo !, 2
.
echo 3, 127
, ;
. ,
. ,
echo !, 2, ...
,
.
nftec/
, , ,
, , , , .
, .
, , ,
, .
, ,
. .
, Windows 95 , Mac OS 9. Windows 98
, .
Web-,
HTML (HyperText Markup Language). , .
.
HTML, ,
Web-. ,
HTML, ,
Web-. HTML.
, Web-, ,
Web-. , Web-,
Web.
- .
, . ,
, .
. , ,
.
Gnfiifiantjfia
,
, .
I. " "
. ,
.
17
V. " "
,
, . Web-,
.
VI. ""
.
, .
/,
,
.
. ,
.
, .
! ,
(, , ) * .
^^?-
18
.
, .
4w , (. ^obtpwiHHO Hi
006
3 / .
.
, .
.
.
.
:
>
>
>
, . ,
. ,
, . , ,
.
, .
, .
, Web. , ,
Web-. .
, ,
. ,
, .
,
.
. Web-.
(Rasmus Lerdof), PHP
Web- (Personal Home Page ).
, .
Hypertext Preprocessing,
Web- .
.
/
Web-. HTML-,
, Web-, .
S . ,
, , .
S .
.
, HTML-.
S . PHP
, Windows, Linux, Mac OS
Unix.
S .
Web- (www.php.net),
, , FHP,
Windows .
news . php . n e t .
S . ,
.
/ .
, , .
, .
PHJ*
.
,
, ,
"" .
, , Web- . W:b,
,
Web-. ,
Web-,
.
Web-.
, Web- (www.php.net/usage.php), 11
. Web- Yahoo!, , ,
, .
Web-
Web- , ..
. Web-, .
,
, . Web- .
, Web-, .
Web- .
, Web-
. , Web-. , .
(server-side language) .
, (, Web-.!).
Web JavaScript. , JavaScript, ;. , JavaScript (client-side language). Web-
" Web" .
22
I.
,
HTML- Web-. , "" Web. , .
,
Web-.
S HTML-.
HTML- , .
S .
, ,
.
J Web-.
Web-,
Web-.
Web-.
, ,
. , -
, , ,
. ,
, .
, JavaScript ,
. , JavaScript
. , ,
. JavaScript
Web-, , .
JavaScript 11.
. ,
- .
. -
. ,
: ,
.
:
dBASE
Informix
Ingres
Microsoft SQL Server
mSQL
MySQL
Oracle
PostgreSQL
Sybase
1. PHP
23
, filePro, FrontEase
InterBase.
ODBC (Open Database Connectivity),
, Access DB2.
Web-,
. PHP-
. ,
Web-. , .
:
, , :
. ,
.
, , , ,
. ,
, .
Web- . , Web- ,
, , , .
. , -
,
. .
:, .
, d i r I s
.
. ,
, , ,
.
, .. , * , .
, , ?
PHP-, , Peri,
, (shell scripts). ,
,
.
/ PHJ*
. ,
.
, .
24
I.
, ,
, , .
.
Web-,
Web. , .
,
CLI. .
,
.
, Perl . ,
CLI, 3.
World Wide W e b
, " ", World Wide Web j
(WWW). Web , Web-. j
Web- . Web- " j
", , URL (Uniform Resource Locator
). URL Web- , )
www.mycompany.com/'
w e l c o m e . h t m l . Web-, 1
URL- . .
|
1. Web- Web .
2. , URL-, .
3. Web-, , .
4. Web- HTML-, URL- .
5. , Web- , ( ]
, Web- .)
6. Web- HTML- Web-.
Web
Web-,
Web-. , Web- Web-.
Web- ,
Web- " ".
Web-.
Web-
(embedded scripting language). , HTML HTML, .. HTML-,
, , .
, Web- ,
PHP- .
.php .phtml, Web-
.
, Web- HTML-
. , PHP-
, .
1.
25
HTML, FHP
, , .
. , .
:
<?php echo "<>3, "; ?>
<?php , ?> IM.
echo , HTML-.
:
<>3,
HTML-,
.
, , Web- . PrIP
Web-,
. Apache Software Foun iation, Web- Apache.
Microsoft IIS/PWS, iPlanet ( Netscape Enterpiise
Server) Web-.
Web-
I
|
|
|
j
!
|
j
i
fne
.
,
, Microsoft, Macromedia Adobe, ,
.
,
. ,
- , ,
,
, .
, , ?
.
26
I.
. ,
, .
,
, . ,
, , .
, , ,
, .
.
,
, .
Web-
. ,
. ,
.
, .
(announcement mailing lists),
. ,
, . , .
, , Web-
w w w . p h p . n e t / m a i l i n g - l i s t s . p h p .
5
, 5,
. ,
. Zend (
), , , .
5 - ,
4.
. , (exceptions). ,
- , ,
5. (- 9.)
5 .
Web p h p - c g i . PHP CLI php, p h p . exe Windows.
, . 5
php. exe, .
5 MySQL 4.1 .
, MySQL 4.0 MySQL 4.1
. 5 MySQL 4.0 .
5 SQLite,
(flat files).
, .
, , ,
.
.
1.
27
S 4.3.1. ,
4.3.0. Web-
4.3.0 .
S 4.3.0. CLI,
( ).
,
.
S 4.2.0. r e g i s t e r _ g l o b a l s
Off. ,
, On , ,
. ,
.
S 4.1.0. . ,
( 6), . 4.1.0
, , , $HTTP_POST_VARS.
, 5.
Web- ! [
.
.
28
I. PhP
/ ...
>
>
>
Web-
Web-
-
, , +S * Web-. ,
Web-,
Web-.
,
Web, .
, Web,
" ".
Haanfiouica Web-
1, Web- Web. , Web- Web-.
Web-
. , ,
. Web- .
.
S Internet.
S ,
, Web-.
S
, .
,
, , ,
. Web , . ,
Web-,
. Web-,
, - ,
,
Web-. , Web-,
. ,
, Web- - .
Web-,
- ( Web-
, Web-).
, , Web-
Web-, ,
Web-.
Web-.
S , .
Web- . ; , . - .
S .
Web, HTML .
Internet, Web-,
.
, .
Web- .
S .
Web- .
S . ,
.
S . , ,
. , , , , , ;;,
- .
S . Web-,
. . ,
. ,
.
Web-
Web-, - ,
Web-. - , . Web-, .
Web-.
Web-
Web-.
S Web-.
, Web- .
Web-, Web- , . ,
, .
S Web-. , .
FTP
. FTP (File Transfer Protocol) :
.
30
I.
Web-.
(user ) .
S , .
URL, . Web , , URL-
. i n d e x . h t m
i n d e x . h t m l , d e f a u l t . h t m . ,
, .
S . Web-
.
.php .phtml,
.
. ,
.
Web-
. Web-, , ,
. , ,
, . ,
, ,
. ,
, .
, ,
. ,
.
, Web-,
.
Web- , .
.
, .
, ,
. , ,
Web-. , , 2
, , , 10 .
,
( ). ,
. ,
, .
, 3.
4.3.1 2003 ,
, 4.3.1
,
. ,
5.
2.
31
.
S . ,
. ,
Bai jero
. , , , .
S . , , Web-.
, . , Web- , ocof ioro
. , .
, ;
.
S .
, .
. . ,
.
, <
.
S . ,
Web- .
, (.
;
,
. , , Good Stuff
, JanetsGoodStuff.
J a n e t s G o o d S t u f f . com, ,
JanetsGoodStuff.Web-hostingcompanyname.com, JanetsGood
S t u f f .Web-hostingcompanyname . com/~GoodStuf f, -
. -, ,
.
/ . :.
. , .
, , .
. (/)
? - ( )
.
.
Web- .
, .
.
. ,
JanetGoodStuff.com,
me@JanetGoodStuf f . com.
32
I.
.
Web-.
, ,
, MySQL
PostgreSQL, Web-, FrontPage,
,
..
.
Web- , ,
Web- ..
S . (backup)
Web- ,
. ,
.
,
- .
Google "webhosting" 4 .
, .
, ,
.
, ,
, .
*j
" "
.
IP-. 0 255, ,
1 7 2 . 1 2 . 2 0 4 . 2 .
IP- , . , IP-
, , a m a z o n . com, www. i r e . g v
m y c o m p a n y . com. , , (domain
name). , , .
, . ,
, t h o r . m y c o m p a n y . c o m ,
(subdomain) m y c o m p a n y . com.
URL-,
Web-, . URL-
, , (, a m a z o n . c o m ) ,
. ( j a n e t . v a l a d e . com).
, Web- ( i n d e x . h t m i n d e x , h t m l ) .
, j a n e t . v a l e d . c o m / l i n k s . h t m l .
, Internet.
, .
, .
. ( ),
.
35 . , .
2.
33
Web-, .
Google " " 2 , i
, . ,
. Web- ,
w h o i s . Allwhois ( A l l w h o i s . c o m ) Better-Whjis j
i (betterwhois.com).
. PHP-
.
. ,
,
marc . t h e a i m s g r o u p . com/.
Web-
Web- , .
. Web- ,
, .
.
Web-,
, .
1. .
2. Web-.
3. .
. , , Web- (
) .
"", 9- ,
"". Web-
, Unix Linux, Windows MacOS.
Web-
, , Web-
. , , Apache,
.
S . ?
S . Apache
Windows, Linux, MacOS, FreeBSD
Unix.
S . ,
www.netcraft.com/survey www.securityspace.com/s_survey/data/,
60% Web- Apache. . !
,
.
34
I.
f . Apache
, .
.
/ .
Apache,
.
/ . ,
Apache SSL.
SSL Web-,
. , ,
Web- , ,
.
.
Apache Linux.
, Apache .
Unix Apache ,
(binary) (
). Windows,
( Apache
Windows NT/2000/XP, Windows 98/).
, Apache 1.3.27.
Apache 2 ,
. www. php. n e t
. Apache,
, ,
h t t p d . a p a c h e . org.
Web-. Microsoft
IIS (Internet Information Server),
Internet: 27% Web-. Sun
iPlanet ( Netscape Enterprise Server),
5% .
.
Linux.
Mac OS X . ,
, .
PHP-. .
S Linux/Unix/Mac.
f i n d / -name "php*"
S Windows. ( ^)
php*.
PHP-, , .
Web- . ,
Apache, .
www. php. n e t . .
2.
35
- , , *
. , ,
.
| S . , . ,
, . :
ODBC,
MySQL, Oracle, MS SQL ; . ,
SQLite, XML, COM, FTP ..,
.
, , ,
.
,
. ,
. ,
, phpinf (), ,
. ,
. ,
. .
S . .
.
php-cgi -v
, , 5, :
php - v
, ,
p h p - c g i . e x e ( php.exe).
:
5.0.0 ( c g i - f c g i ) , Copyright () 1997-2003 The PHP Grotp
Zend Engine v 2 . 0 . 0 . Copyright (c) 1998-2003 Zend Technologies
,
. ;
www. php. n e t /downloads . php.
,
.
1. , .
.
Apache h t d o c s .
, Web-. IIS
lnetpub\wwwroot. Linux /var/www/html.
Web- , Web-
- , ,
. ,
.
36
I.
2. t e s t . p h p :
<html>
<head>
<title>TecpoBaHne PHP</title>
</head>
<body>
<> HTML
<?php
echo "<> </>";
phpinf();
?>
</body>
</html>
3. URL- t e s t . p h p ,
. 2.
URL h t t p : / / w w w . m y c o m p a n y . c o m / t e s t . p h p . Web, ,
URL- l o c a l h o s t / t e s t . p h p .
A^'g^N
,
Web-, .
:
HTML
,
. ,
, .
p h p i n f ( ) .
, ,
. p h p i n f () .
- ,
.
S HTML.
.
S .
/ Web-.
,
, ,
. .
,
, . ,
,
php-cgi -v
php - v
2.
37
, , , [.
, , . 3.
, ,
. 1. Apache h t t p d . c o n f
DocumentRoot ":/Program Files/Apache Group/Apache/htdocs"
Apache, Web-.
. Web-)
j a n e t . v a l a d e . com.
, , , .
, .
.
S Web- , IP.
, h t t p d . conf
AddType a p p l i c a t i o n / x - h t t p d - p h p .php
S Apache,
. php. ES ,
, .
S h t t p d . c o n f ,
. ,
.
S IIS, php. i n i :
cgi.force_redirect =
S p h p . i n i . ,
, . 1 0.
, , , -
Web-.
, , , :
.
- , .
marc . t h e a i m s g r o u p . com/. , - )
, .
. .
S
S
S
S
, .
, .
.
, Web-.
, . 18 .
38
I.
(cli)
( b u i l t : J u n 1 5 , 2003 2 3 : 0 7 : 3 4 )
, ( c l i ) .
Web,
( c g i ) .
CLI. ,
, , .
CLI, .
, Web.
, CLI.
Web-,
, PHP-
Web CLI. , ..
5.0.0 Web, , CLI 5.0.0.
Windows p h p 5 t s . d l l ,
. , p h p 5 t s . d l l . (
.)
Hacfnftoutca THJ*
.
. ,
. -
2.
39
p h p . i n i . ,
.
, php. i ai.
, . , . , (, ), php. i n i . 1
, .
,
. ,
, .
cfteqctn
, PHT-cu^Hafiuee
PHP- . ,
.
v i , Notepad WordPad. ,
, .
(Integrated Development Environment).
, <.
,
. , ,
.
.
.
S . ,
HTML, , ,
.
S .
.
S .
,
. 872
, .
S .
.
S .
, HTML .
S . -,
.
40
I. Pt'P
Internet .
.
S Arachnophilia ( w w w . a r a c h n o i d . c o m / a r a c h n o p h i l i a / ) . Java
.
S BBEdit (www.barebones . c o m / p r o d u c t s / b b e d i t / i n d e x , shtml).
.
BBEdit 179 .
BBEdit Lite. ,
. BBEdit Lite
TextWrangler, 49 .
S EditPlus (www.editplus.com).
Windows.
EditPlus - ,
30 .
S Emacs (www.gnu.org/software/emacs/emacs.html). Emacs
Windows, Linux Unix
.
f HomeSite (www.macromdia.com/software/homesite/). HomeSite
Windows
99 .
V HTML-Kit ( w w w . c h a m i . o m / h t m l - k i t / ) .
Windows, .
S vim gvim: (www.vim.org/).
v i Windows, Linux, Unix
MacOS. gvim ,
Windows .
(Integrated Development Environment )
.
.
, .
S .
.
S . Web-,
.
S . .
S FTP. FTP
. , Web-,
.
S . ;
, .
S . ()
Web-.
2.
41
,
. , .
,
.
.
.
| S Dreamweaver MX (www.macromedia.com/dreamweaver).
Windows.
, Web, COOTI . Dreamweaver HTML-
. HomeSite,
, .
Dreamweaver 399 .
S Komodo (www.activestate.com/Products/Komodo/). Komodo
Windows Linux. '
, Perl, Python,
. 29,95
295 .
S Maguma (www.maguma.com). Maguma Windows.
Apache, PHP MySQL
Windows.
, Maguma Studio Desktop Maguma Studio Enterprise, /
,
. Maguma Studio
.
S PHPEdit ( w w w . p h p e d i t . n e t / p r o d u c t s / P H P E d i t / ) . Windows.
/ Zend Studio (www. z e n d . c o m / s t o r e / p r o d u c t s / z e n d - s t u d i o . p h ? ) .
Zend Studio Windows Linux.
,
Zend . Zend Studio 195 .
Web- ,
,
p h p e d i t o r s . l i n u x b a c k u p . c o . u k .
111 .
42
I.
/ &...
>
>
>
>
HTML
, ,
. PHP-
. ,
- .
.
- , .
1, ,
, . Web-
, Web-.
, Web-,
. ,
Web-. ,
, Web-
, .
, . ,
, , .
, .
, . , ,
.
onefiatfiofioe !PH!P
, .
echo. .
echo:
echo "";
echo , ("").
.
echo (simple statement).
(;).
, ; ( ,
). . ,
, . .
,
. :
Parse error: expecting ' , ' " or ' ; ' ' in f i l e . p h p on l i n e 6
, , .
, ,
, .. .
,
. aHanj . , ,
. ,
. 553 ,
. ,
, .
, > .
. , .
,
({ }). , .
, i ; . :
if (_ == )
{
;
;
;
}
,
. , .. _ = , ,
. ( ,
, ).
, (, , i f ) ,
(complex statement).
, .
.
, , .
. , , . , ci ;, , .
,
.
.
/
, .php. ,
, . ,
.
44
I.
Web- -
HTML- Web-.
Web, , .
, .
| HTML ( . h t m l . h t m ) , Web-
: . , ,
H T M L Web-. |
( . p h p ) , Web- ( ).
.
1. Web- HTML, .. i
HTML, .
| 2. HTML ,
|
(<?php).
|
3.
< ? p h p , Web- . , I
< ? p h p , Web- PHP-
. , ,
.
| 4. Web- ,
(?>).
| 5. ?>, Web- HTML
, . 1.
HTML-
Web-
HTML- Web-.
. php, Web- . ( Web ,
, .php4 .phtml. .php
, .)
HTML , ,
HTML. :
<?php
?>
<? ?>,
.
,
php . i n i .
. , Web- ,
, PHP- ,
.. .
3.
45
, ,
Web- . ) ICT , Web-. , ,
(.. ) HTML
. .
, HTML .
. php:
<?php
Web- . php
. <?php, Web-
echo, . , , .
, .
, , .. File^Opeii^
Browse (^^).
URL- , 2.
Web- PHP-.
.
HTML
<?
echo " ";
?>
HTML
<?
echo " ";
?>
Web
, . Web. CLI (Command Li ie
Interface ). CLI ,
Web- ( CGI),
. CLI
CLI , , ;
, Unix Linux.
, Windows,
( ).
CLI
Linux/Unix, Windows. (
.)
:
<?php
echo " ";
?>
46
I.
i 4
> 4^-
Linux/Unix
#! /usr/bin/php
\ <?php
echo " " ;
! ?>
| , ,
/ u s r / b i n / p h p . Windows ,
. # ! / u s r / b i n / p h p Linux/Unix, |
, Windows .
I . , |
j , . , , '
| , t e s t . p h p ,
j test.php
; :
/mystuff/test.php
j He , , ,
.
t e s t c l i .php,
( , , CLI):
php t e s t c l i . p h p
:
/usr/local/php/cli/php testcli.php
Windows,
.
StartoPrograms^Accessories^Command Prompt (^^1^ ).
CLI CGI .
S HTTP. CGI
Web-, ,
HTTP (, Web-
). ,
CGI :
Content-type: text/html
X-Powered-By: PHP/5.0
,
Web-. , CLI
HTTP, :
3.
47
S . PHP CGI
HTML,
, , .
PHP CLI .
/ argc arirv.
a r g c a r g v
( ).
CGI, CLI , .
CLI 31.
( a r g c a r g v 5.)
(). , - v .
:
php -v
. 3.1 .
3.1.
p h p . i n i . CLI
p h p . i n i , - / u s r / l o c a l / p h p / c l i / p h p . i n i (
p h p . i n i .)
. , php -
-h
-i
, p h p i n f ()
-1
. ( 14.)
, .
, php - r ' p r i n t ( ' ' ) ; '
/myfiles/testcgi.php
(. 2)
-v
/ nefi0oio / THJ*
, >
, . HTML, , ,
:
<html>
<headxtitle>HTML-nporpaMMa</titlex/head>
<body>
<>3, !</>
</body>
</html>
, :
, !
48
I.
.
, HTML PHP-
, !
<html>
<headxtitle>CueHaprai P H P < / t i t l e x / h e a d >
<body>
<?php
echo "<>3, !</>";
?>
</body>
</html>
, HTML.
, , ..
File^OpenO
Browse (^).
URL- (. 2).
, , ,
URL-.
:
<?php
echo "<>3, !</>"
?>
echo, , (" ").
,
:
<>3, !</>
PHP- , HTML-.
, , ,
( ,
View=>Source ( HTML-)).
3.
49
S _ (, 1
250) .
5.
S . ( 5 ,
.)
S echo .
S echo (,)
.
S ,
.
. 3.2 echo.
3.2. e c h o
echo 123;
echo
echo
echo
echo
", !";
",","!";
",", " ","!";
, !;
123
3 , !
,!
, !
,
, !
, , !,
, HTML,
. ,
1. ,
Web-, , , .
HTML-, ,
-.
2. Web-
HTML- Web-.
HTML- "" .
, , Web-
, .
echo, <
, !:
echo "<>3, !</>", , (""). -
.
1. echo :
<>3, !</>
50
I.
. ,
Web-, HTML. :
<>3, !</>
echo ,
.
\. :
echo "<>3,\ !</>"
\ echo ,
. Web-
<br>. :
echo "<>3,<br> !</>"
.
. 3.3 echo
: Web-.
echo.
(.. , ), ,
.
3.3. -
e c h o
echo
echo
echo
echo
", !";
",";
"!";
",\!";
echo ",<>!
echo ",<>\!";
, !
, !
, !
,!
,
!
,<>!
, !
,<>
,
!
,
. ,
, echo.
, , .
echo. ,
,
. ,
3.
51
\! . , \
(.. ),
.
\.
HTML- . , ,
, .
, HTML- ; . -,
, HTML Web-.
,
. \ HTML . ,
.
, . ,
.
, . Web,
HTML.
, Web, :
.
2)//{1,
.
, . ,
, .
, ,
. , , i
. , -
, , .
(comments) , .
.
. :
/*
*/
(/*),
* /.
,
, . :
/*
:
:
:
:
:
hello.php
", !"
Web-
02/01/03
03/15/03
*/
.
(#) (//).
. :
52
I.
# 1
/ / 2
# / / ,
. .
:
echo ""; / /
, HTML-,
, .
,
:
/* , 18 */
/* */
/* */
, .
:
################################
# #
################################
, . ,
, :
.
( ) . ,
, echo, ,
, . ,
.
, .
. :
/*
/* */
*/
, /*,
, */.
/*. , ,
/* */. */,
, .
3.
53
II
W , W W .
/3 /
. ,
, .
,
, .
Sfflou
>
>
>
>
>
...
(variable) , .
,
. , $ 21.
.
Web
, HTML, .
Web , " , !"
,
. , .
iLueHa nefieutettHbtx
, , .
, $ v a r l , $var2, $var3 ..
, , , -
,
. , ,
, .
, ,
$f irstName, $ d i r e c t o r y _ n a m e $DateOfBirth.
.
| S ($).
.
S .
S ,
.
/
. .
f .
$ f a v o r i t e c i t y $ F a v o r i t e c i t y . :
$ F a v o r i t e C i t y , ,
$ f a v o r i t e C i t y .
:
$_name
$first_name
$name3
$name_3
:
$3name
$name?
$first+name
$first.name
, , . , , .
.
.
:
$first_name
$firstName
. .
.
otiiorffiajtcetiue
nefieueHHbtx
.
, .
. , \.
, , . ,
, .
,
.
.
, (=) . ,
:
$ = 21;
$price = 20.52;
$temperature =-5;
$name = " ";
58
//.
, , ,
, . ,
, .
, ,
.
5.
, ,
. , , :
$color "";
$color = "";
" ".
$ c o l o r " ".
,
:
$namel = "";
$name2 = "";
$favorite_name = $name2;
$ favor i t e_name
"".
, . ,
:
$ c i t y = "";
, .
5.
p r i n t _ r . :
$today = "";
print_r($today);
.
echo.
$ = 2 1 ;
echo $age;
21.
echo ,
p r i n t _ r . echo .
, . ,
, $name .
HTML- :
<> , <?php echo $name?>/p>
Web- :
,
,
. , ,
$, :
echo $aeg;
4.
59
:
Notice: Undefined v a r i a b l e : aeg in c : \ t e s t v a r . p h p on l i n e 5
(Notice) ,
. ,
. .
, (
). ,
( 7).
, . ,
@. ,
, :
echo @$aeg, , . ,
, , echo .
, . , i
,
. ,
, .
, .
4S2&
'"-^
,
.
,
. ,
, Java .
/ [1,
, 3, Web- ,
echo. ,
, . 3
:
<?php
echo "<>3, ! </>";
?>
,
", !":
<html>
<head> <title>CueHapmi nepeMeHH0H</titlex/head>
<body>
<?php
$salutation = ", !";
echo "<p> $salutation </p>";
?>
</body>
</HTML>
, Web-
, !
60
II.
,
-. 5 ,
5 (, ,
). , :
<html>
<headxtitle>CiJ,eHapira nepeMeHHOH</titlex/hea6>
<body>
<?php
$salutation = ", !";
echo "<p> $salutation </p>";
?>
<> HTML</p>
<?php
echo "<p>$salutation </>";
?>
</body>
</HTML>
URL- , Web-
:
, !
HTML
, !
",$last_name;
?>
$f i r s t _ n a m e $last_name.
, :
, ,
. . 4.1
echo, , .
echo :
$number = 12 3;
$wordl = ",";
$word2 = "!";
,
, .
.
4.
61
. 4.1. echo
e c h o
echo $number;
echo $word,$word2;
echo $wordl," ",$word2;
123
,!
, !
echo $ w o r d l $word2;
,
.
, !
echo ,
.
. , ,
$type = " b i r d " ;
echo "Keep the $typecage clean";
:
Notice: Undefined v a r i a b l e : typecage i n testvar.php on l i n e 6
:
Keep the c l e a n
, echo
:
echo "Keep t h e {$type}cage c l e a n " ;
:
Keep the b i r d c a g e c l e a n
/ /
,
. , ,
, .. .
, , $ c i t y -.
:
$name_of_the_variable = " c i t y " ;
, ,
.
$$name_of_the_variable = "-";
. "
. , , $name_of _ t h e _ v a r i a b l e :
$ c i t y = " ";
$name_of _ t h e _ v a r i a b l e .
. >
,
.
, .
6 7.
62
II.
, ,
, ,
. :
$Reno = 3 6 0 0 0 0 ;
$Pasadena = 13 8000;
$cityname = "Reno";
echo " $cityname - ${$cityname}";
$cityname = "Pasadena";
, echo
. .
$ = ;
$. ,
$ 0. , $
. , $
. $ echo,
. ( .)
:
unset($age);
$ .
echo,
"undefined v a r i a b l e " ( ). ,
:
unset($age, $name, $address);
Padotna c icoHctiiaHtnaMU
. .
; .
, .
"",
.
d e f i n e .
:
define (" _" , " _") ,, weather, :
d e f i n e ( " w e a t h e r " , "");
w e a t h e r .
4.
63
, ,
. , ,
. ,
,
. .
.
INTEREST . 0 1 :
define("INTEREST",.01);
, .
, echo.
, PHP-,
. ECHO, ,
. , \
e c h o ECHO;
.
echo, ,
echo.
:
and
echo
list
as
else
new
break
empty
or
case
eval
print
class
exit
require
const
for
return
continue
foreach
switch
declare
function
use
default
global
var
die
if
while
do
include
, , < > ,
. , ,
- . , .
, { , $.
, ,
.
, -
, .
. ,
PR0DUCT_COST , 20.50.
. - ,
,
. ,
. .
64
II.
,
- .
, ,
, . ,
1.52, :
<?php
$US_dollars = 20.00;
$CA_dollars = $US_dollars * 1.52;
?>
, 40 000
50 . ,
50 . ,
, ,
, 1.52 50 . ,
.
,
. :
<?php
$ r a t e = 1.52;
$US_dollars = 20.00;
$CA_dollars = $US_dollars * $ r a t e ;
?>
$ r a t e , 50
. , .
, .
, 1.53,
:
$ r a t e = 1.53;
. $ r a t e . ,
40 000 2 ,
, 50 . , -
,
. , - :
$ i n t e r e s t _ r a t e = 20;
$rate = $interest_rate-l;
$amount = $ p r i n c i p a l * $ r a t e ;
$ r a t e .
1.52, , 19,
. , .
, :
<?php
define("RATE", 1.52);
$US_dolars = 20;
$CA_dollars = $US_dollars * RATE;
?>
RATE, .
RATE = 20;
. ,
.
4.
65
, 1. 53,
:
<?php
define("RATE", 1.53);
$US_dollars = 20
$CA_dollars = $US_dollars * RATE;
?>
, , :
define("US_TO_CA", 1.52);
, ,
, , ,
, ,
.
,
, .
, .
p r i n t _ r :
print_r(US_TO_CA);
echo:
e c h o US_T0_CA;
echo,
. ,
, . ,
, .
, , :
echo " $",US_T0_CA;
:
$1.52
, >
. , LINE ,
FILE
. (
.) ,
echo
FILE ;
:
c:\program f i l e s \ a p a c h e g r o u p \ a p a c h e \ h t d o c s \ t e s t v a r 2 . p h p
. ,
E_ALL E_ERR0R .
.
66
II.
d:\testl.php on l i n e 9
, ,
p r i n t _ r .
,
. .
S (notice). ,
, ,
.
. :
N o t i c e : Undefined v a r i a b l e : age i n t e s t i n g . p h p on l i n e 9
,
, .
. ,
. ( ;
.) ,
, ,
.
, , .
Web-
Web- php. i n i .
p h p . i n i ,
. ,
,
4.
67
. ( , p h p . i n i ,
.)
, p h p . Lni
, :
e r r o r _ r e p o r t i n g = E_ALL; d i s p l a y a l l e r r o r s , w a r n i n g s a n d n o t i c e s
( , )
. 1 '
.
.
,
E_ALL, . , ]
p h p . i n i .
, . ,
.
p h p . i n i , ,
. ,
. p h p . i n i 1
.
E_ALL , ,
; E_NOTICE , .
:
e r r o r _ r e p o r t i n g = E_ALL & ~E_NOTICE
E_ALL ,
. ~E_N0TICE ,
.
.
, , .
, , .
, .
E_ALL E_NOTICE .
p h p . i n i .
IP.
.
1
,
.
. .
, p h p . i n i d i s p l a y _ e r r o r s = On On Of f.
>
, p h p . i n i Web-.
,
error_reporting() ;
68
//.
, .
, ,
, :
error_reporting(E_ALL);
, php. i n i
E_ALL.
, .
, php. i n i ,
error_reporting(E_ALL & ~E_N0TICE) , ,
.
error_reporting(0) ;
. , ,
,
.
. 0,
,
. , .
.
.
.
.
p h p . i n i , . p h p . i n i
l o g _ e r r o r s = Off
Off On. ,
. ,
; e r r o r _ l o g = _
,
. _ ,
. ,
error_log = c:\temp\php_error_log
( Windows
). ,
: \temp. .
, .
(D
php . i n i ,
Web-.
4.
69
.
. ,
, .
.
, ,
. , . , (
, $ h e i g h t _ o f _ d o o r ,
$ h e i g h t _ o f _ _ h o u s e , . ,
. .
, :
if ($height_of_door > $height_of_house)
{
trigger_error("Impossible
condition",
E_USER_ERROR);
i f 7.
E_USER_ERROR , .
I m p o s s i b l e c o n d i t i o n , . , :
F a t a l e r r o r : I m p o s s i b l e c o n d i t i o n i n d : \ t e s t e r r . p h p on l i n e 9
, ,
, .
E_USER_ERROR E_USER_WARNING E_USER_NOTICE, .
,
,
, , . ,
:
if ($height_of_door > $height_of_house)
{
e c h o " <>";
e x i t () ,}
$ h e i g h t _ o f _ d o o r $ h e i g h t _ o f _ h o u ,
e x i t () .
.
,
e r r o r _ l o g ( m e s s a g e , 3 , __) ,if
, i f :
($height_of_door > $height_of_house)
error_log
exit();
(" " , 3 ,
"/temp/err_log");
, $ h e i g h t _ o f _ d o o r
$ h e i g h t _ o f _ h o u s e , / t e m p / e r r _ l o g
. 3
70
II.
. /temp .
, .
.
, ,
e r r o r _ l o g . 1 e r r o r _ l o g
:
e r r o r _ l o g (" ", 1, "me@mymail.com");
,
PHP-. 13.
, . ,
. , ,
. ,
.
. ,
.
. (
8.)
, ,
set_error_handler(_);
, :
set_error_handler(my_error_handler);
m y _ e r r o r _ h a n d l e r
8.
d i e , .
8.
4.
71
/ ...
>
>
>
>
. ,
. ,
1+2. (+)
-. ,
.
/
.
*
(integer) (
), -43, 0, 1, 27 543 8.
.
-2 2 .
S (floating point)
, 5 .24 123 .456789.
(real number) (flc at).
S (string)
, .
- .
S () (boolean) : TFUE
() FALSE (). .
,
.
. . --
, ,
. .
,
.
:
: T R U E () F A L S E ().
. , $>$
TRUE (), FALSE ().
.
" F A L S E " ( , );
0;
. ;
;
, " " ;
NULL.
TRUE.
echo , F A L S E , 1 -
. .
, .
8.
.
, :
$firstNumber = 1 ;
#
$secondNumber = 1.1;#
$sum = $firstNuinber+$secondNumber;
, ,
.
f l o a t ,
. , .
.
.
.
(type casting). :
$newint = ( i n t ) $ v a r l ;
$newfloat = ( f l o a t ) $ v a r l ;
$newstring = ( s t r i n g ) $ v a r l ;
, ,
, . , $ v a r l
$newint i n t e g e r ( ( i n t ) ) .
.
. ,
. , $number
1. 8, $newnumber
= ( i n t ) $number $newnumber 1.
var_dump ($myvariable) , 5.
73
, $checkvar:
var_dump($checkvar) ;
i n t (27), ,
$checkvar 27.
Padotna
f l o a t i n t e g e r .
:
$intvar =3;
$floatvar =9.3;
.
.
, (+) :
1+2
:
$varl + $var2 ;
. ,
. ;
. :
$varl = " 1 " ;
$var2 = 2;
$ t o t a l $varl+$var2;
$ v a r l $var2 , $ v a r l
.
" 1" 1 .
, :
$varl = "";
$var2 = 2;
$total = $varl+$var2;
" " , 0. , 1
$ v a r l $var2 2. -IT
. , :
.
, ,
.
,
. :
74
II.
$varl = "2,000";
$var2 = 2;
$total = $varl+$var2,-
,
. "2,000" 2,
$ t o t a l 4.
. 5.1 .
5.1.
( ). ,
$ = 13%4 $ 1
. ,
:
$ t o t a l = 1+2*3+1, ,
.
.
. , $ t o t a l 8.
$ t o t a l = 1+2*3+1 #
$ t o t a l = 1+6+1
# -
$ t o t a l = 7+1
# -
$total = 8
.
. , :
$ t o t a l = (l+2)*3+l;
$ t o t a l
10:
$ t o t a l = (l+2)*3+l #
$ t o t a l = 3*3+1
#
$ r e s u l t = 9+1
#
$ r e s u l t = 10
. , (3+2*5) ,
. ,
.
" "
,
.
5.
75
1 :
$counter $ c o u n t e r + l ;
:
$counter++;
,
$counter=0;
$counter++;
echo $counter;
$ c o u n t e r 1 (
). :
$counter--;
1
: "+=1". . :
$counter+=2;
$counter-=3;
$counter*=2;
$counter/=3;
$ c o u n t e r Hi. 2,
3, 2 3 .
. ( 8.) ,
, ,
. :
$rootvar = sqrt(91);
$rootvar = sqrt($number);
91, ,
$number.
$upnumber = ceil(27.63);
28. ,
. :
$downnumber = floor(27.63);
f l o o r () 27.
:
, , ,
,
.
- ,
76
II. \
.
. , 10.00, 10.
, .
number_f ormat ()
number_format(, __,
"!",
"2")
:
S . , .
^ __. .
, 0 ,
, (..
). I !,
__ .
S . ,
- .
. ! ,
!.
S !. ,
. .
. 5.2 number_f ormat ( ) .
5.2. number_f ormat ()
$number
12321
12321.66
12321.66
12321.6
12321
12321.66
number_format($number)
number_format($number, 2)
number_format($number)
number_format($number, 3)
number_format($number, 0,
number_format($number, 2,
12,321
12,321.66
12,322
12,321.600
12.321
12321.66
.
.
p r i n t f ()
s p r i n t f ().
S p r i n t f () .
S s p r i n t f .
p r i n t f () s p r i n t f () ,
. ,
" ".
5.
77
Parfo/na cfnfiOKcuiu
(character) , . (1
) (character string) .
, , , ..
. ,
, .
. :
. , :
$ s t r i n g = ", !";
$ s t r i n g = ', ! ' ;
-~ ^.'"'
|^ * ^
'"
\. neredoc-,
] , . :
t :
[ $_ -
<
j
[;
\
I
|
|
. $_
, .
, , !
$_.
j , neredoc-, ;
| . ( *
I " ".)
i /-.
I $distance = 10;
{ $herevariable = <ENDOFTEXT
j
i -
j $distance .
| ENDOFTEXT;
j echo: $herevariable;
j $ h e r e v a r i a b l e :
j
| /-
I 10 .
)
\
|
\
j
i
i
. 3
. (
E N D O F T E X T ) , , ;
. : ,
. , , PHI1
.
78
II.
, \ \ t ,
. \ . :
$ s t r i n g = ", \";
echo $ s t r i n g ;
:
,
\ t . ,
$ s t r i n g = " 1 \n\tcTpc-Ka 2 " ;
echo $ s t r i n g ;
, :
1
2
,
.
.
.
.
S , ,
" ", \ ',
. ( .)
S
, .
.
,
, . :
$name = "";
$outputl = "$name";
$output2 = '$name';
echo $outputl;
echo $output2;
$name
.
, ,
- . :
$ s t r i n g l = " \\ ";
$ s t r i n g 2 = ' \\ ';
5.
79
:
:
\\
,
. :
$number = 1 0 ;
$stringl = " '$number' .";
$string2 = ' "$number" .';
echo $stringl, "\n";
echo $string2;
:
' 1 0 ' .
"$number" .
, , , $ s t r i n g l
$number ,
, . .
, ,
.
,
" ", .. . , ,
,
. ^
(backslash) (\). :
$ s t r i n g = ' $ v a r l ' ;
$ s t r i n g = " - \ $ v a r l " ;
:
i s $ v a r l *
, , :
$ s t r i n g = ' '?';
echo $ s t r i n g ;
, ;
('), .
:
,
, . , ..
:
$string s ' 0\'?';
, , ,
", \.
80
II.
(concatenation).
(.).
:
$ s t r i n g l = ",";
$ s t r i n g 2 = "!";
$stringall = $stringl.$string2;
echo $ s t r i n g a l l ;
:
,!
, (""),
.
:
. :
$stringall = $stringl." ".$string2;
. =.
, :
$ s t r i n g a l l = ",";
$ s t r i n g a l l .= " !";
echo $ s t r i n g a l l ;
:
, !
.
( 8.)
,
, , ..
.
:
$ s t r i n g = t r i m ( $ s t r i n g ) #
$ s t r i n g = l t r i m ( $ s t r i n g ) #
$ s t r i n g = r t r i m ( $ s t r i n g ) #
s t r _ w o r d _ c o u n t ()
:
str_word_count("", )
: 1 2. 1
str_word_count () ,
. 2
, . (
.) ,
s t r _ w o r d _ c o u n t () .
:
$ e t r i n g " ";
$numberOWords = s t r _ w o r d _ o o u n t ( $ s t r i n g ) ;
5.
81
$wordl = s t r _ w o r d _ c o u n t ( $ s t r i n g , 1 ) ;
$word2 = s t r _ w o r d _ c o u n t ( $ s t r i n g , 2 ) ;
:
$numberOfWords = 2
$wordl[0] =
$wordl[l] =
$word2[0] =
$word2[9] =
, 0 ( 1, ivor ), 9.
6 .
,
, . 5.3. , , .
. , -
echo ,
. :
$number = 4 ;
echo " $number .";
:
4 .
$number 4, echo
.
.
echo . "
" number_f ormat (),
. ^ . p r i n t f () s p r i n t f ()
, , .
p r i n t f () s p r i n t f () :
printf("", $_1, $__2,
...);
$newvar = sprintf("", $_1, $_2,
...);
p r i n t f () ,
s p r i n t f () .
, . 5, $_.
, :
$newvar = s p r i n t f ( " , !");
, ,
! $newvar.
, :
--1?nboys = 3 ;
$ n g i r l s = 2;
p r i n t f ( " % s %s ", $nboys, $ n g i r l s ) ;
82
II.
5.3.
$ = str_repeat("", 5) ;
str_repeat("", )
str_replace
$ = "abc abc";
b
("", "
$s = str_replace("b", "i", $a);
"")
strchr
$str = "aBc abc";
,
("",
"")
$sub = strchr($str, "b");
stristr
$str = "aBc abc";
s t r c h r ( ) ,
{"", "")
$x = xxxxx
$s = aic aic
$sub = be
$sub = Be abc
$n = 6
$n = 2
$sub = be
$n = edeba
$n = 5
$str =
$str =
$new = aa xx cc
$sstr =
$n = 2
$ t = abxbc
$str2 =
$str2 = Aa Bb Cc
%s ,
p r i n t f () . ,
3 2 .
% p r i n t f ,
. :
%-.
.
S (%) .
S . -,
( ).
( ), 0
, .
- 01 0001.
S (-).
, ( ).
S . >ix
, . , 5,
0,
1, 00001
S
. . ,
.
S . s (string).
f (float).
s p r i n t ( ) .
$money = 30;
$pet = " K i t t e n " ;
$new = sprintfC'It costs $%03.2f for a %s.\n", $money, $pet);
$new2 = sprintf("%'.-20s%3.2f", $pet, $money);
echo $new;
echo $new2;
.
I t c o s t s $030.00 for a K i t t e n .
Kitten
30.00
, $money f 3.2 f ( ). :
, $new $new2.
$new $money 0, $new2 .
$pet $new2 ' . -20.
20 ,
$pet. K i t t e n ,
- (' .), ..
14 (.). (-) , K i t t e n
. .
. , , : 12 . :i,
1 234.55. echo :
84
II.
12.3
1
234.55
number_f ormat ()
:
12.30
1.00
234.55
printf():
p r i n t f ( " % 5 . 2 f \ n " , $numberl);
p r i n t f ( " % 5 . 2 f \ n " , $number2);
p r i n t f ( " % 5 . 2 f \ n " , $number3);
:
12.30
1.00
/
234.55
%5. 2f \. .
S %. .
/ 5. , .. ,
. 5,
- ( ).
,
.
S 2. .
S f , .
/ \. .
( $),
s p r i n t f (). :
$newvariablename = s p r i n t f ( " $ % . 2 f " , $oldvariablename);
$ o l d v a r i a b l e n a m e ,
$newvariablename.
:
$ p r i c e = 25;
printf("$%.2f", $price);
:
$25.00
qounbt [
.
.
timestamp . ,
.
5.
85
d a t e ( ) .
. d a t e
:
$mydate = date("", $ times tamp);
$ t i m e s tamp .
, time () mktime ().
$ times tamp , . :
$today = d a t e ( " Y / m / d " ) ;
10 2004 ,
:
2004/03/10
.
, y - m - d d a t e () 0 4 - 3 - : . 0 ,
M . d . Y M a r . 1 0 . 2 0 0 4 . . 5.4 ,
. (
Web- www. p h p . n e t . )
(-), ( . ) , ( / ) .
5.4.
Jan
January
( )
02 12
(- )
1 12
( )
0 1 14
( )
, 0 () 6 ()
( )
( )
3
Friday
Fri
5
2004
04
(12- , 1 12)
2 10
(24- , 23)
2 15
(12- , 0 1 12)
0 1 1 0
(24- , 0 23)
00 23
00 59
00 59
86
II.
. 5.4
: am ( )
am
: A M ( )
AM
1056244941
timestamp
timestamp
time ():
$today = t i m e t ) ;
$today = strtotime("today");
timestamp
mktime (). :
$importantDate = mktimefh, m, s, mo, d, y ) ;
h ; m ; s ; mo ; d ;
. , , 15 2004 ,
:
$importantDate = mktime(0, 0, 0, 1, 15, 2003);
timestamp
. ,
:
$importantDate = s t r t o t i m e ( " J a n u a r y 15 2003");
s t r t o t i m e () .
S : 12 .
S : 7 .
S : y e a r (), month (), f o r t n i g h t (
), week (), day (), hour (), m i n u t e (), second
(), am ( ), ( ).
/ : ago ( ), now (), l a s t (),
n e x t (); t h i s (), tomorrow (), y e s t e r d a y ().
S "" "".
S .
S : , gmt (Greenwich Mean Time
) pdt (Pacific Daylight Time ).
- . :
$importantDate = s t r t o t i m e ( " t o m o r r o w " ) ;
# 24
$importantDate = s t r t o t i m e ( " n o w + 24 h o u r s " ) ;
$importantDate = s t r t o t i m e ( " l a s t S a t u r d a y " ) ;
$importantDate = s t r t o t i m e ( " 8 p m + 3 d a y s " ) ;
$importantDate = s t r t o t i m e ( " 2 weeks a g o " ) ;
#
$importantDate = s t r t o t i m e ( " n e x t year gmt");
#
$importantDate = s t r t o t i m e (" tomorrow 4am"),-
5.
87
IHO
. , $ i m p o r t a n t D a t e
, "" :
$ t o d a y ( ). :
$timeSpan = $today-$importantDate;
.
:
$timeSpan = ( ( $ t o d a y - $ i m p o r t a n t D a t e ) / 6 0 ) / 6 0 ;
88
II.
/
>
>
>
>
>
...
,
. , $FordInf
, , .
, .
, .
, ,
.
fiarfoina
.
, , .
. ,
, . ,
$customers , .
$customers
$customers[1]
= " ";
.
$ c u s t o m e r s 1, 2 3. .
,
:
$ c a p ' i t a l s [ ' ' ] = "";
$ c a p i t a l s [ ' T X ' ] = "";
$ c a p i t a l s [ ' O R ' ] = "";
,
. ;
$ s t r e e t s [ ] = ". ";
$ s t r e e t s [ ] = ". ";
$ s t r e e t s [ ] = " 7 - ";
,
0. ,
:
echo " $ s t r e e t s [ 0 ] " ;
.
0,
.
1, 0.
$ s t r e e t s = ( " . " , " . ", " 7 - " ) ;
,
. , , , , [
12, 0,
$ s t r e e t s = a r r a y ( 1 2 => " . " , " . ", " 7 - " ) ;
$streets[12]
$streets[13]
$streets[14]
:
= ". ";
= " . ";
= " 7 - ",-
. ,
:
$ c a p i t a l s = a r r a y C ' C A " => "",
"" => "",
"OR" => " " ) ) ;
.
.
.
, ,
.
.
,
. :
$years = range(2001, 2010);
:
90
II.
$years[0] = 2001
$years[l] = 2002
$years[8] = 2009
$years[9] = 2010
$reverse_letters = range("z", "a");
26 :
$reverse_letters[0] = z
$reverse_letters[1] =
$reverse_letters[24]
$reverse_letters[25]
= b
= a
: v a r _ d u m p () p r i n t _ r ( ) . p r i n t _ r () .
$ c u s t o m e r s :
print_r($customers) ;
:
Array
(
[1] =>
[2] =>
[3] =>
)
, .
v a r _ d u m p ( ) :
var_dump($customers) ;
:
array(3){
[1]=>
s t r i n g ( 9 ) " "
[2]=>
s t r i n g ( 9 ) " "
[3]=>
s t r i n g ( 1 0 ) " "
}
(, ). , ,
,
v a r _ d u m p () :
array(2){
["name"]=>
s t r i n g ( 9 ) " "
["age"]=>
int(12)
>
i n t .
a g e 12.
6.
91
,
. Web
p r i n t _ r () var_dump ()
HTML, .. .
;
HTML-, :
echo "<>";
var_dump($customers);
echo "</pre>";
, .
, . ,
$ c a p i t a l s , :
$capitals[''] = " ";
" ",
(Austin) ( ).
$ c a p i t a l s :
$ c a p i t a l s [ ' R I ' ] = "";
, .
, , :
$customers[1] =
$customers[2] =
$customers[3] =
$customers[] = " ";
$customers :
$customers[1]
$customers[2] =
$customers[3] =
$customers[4] =
, :
$customerCopy = $customers;
. , ,
$colors = array("", "", "", "", ""));
. ,
. :
$ c o l o r s [ 3 ] = "";
$ c o l o r s [3] ,
. $ c o l o r s ,
. , :
unset($colors[ 3 ] ) ;
92
II.
$ c o l o r s :
$ c o l o r s [ 0 ] =
$ c o l o r s [ l ] =
$ c o l o r s [ 2 ] =
$ c o l o r s [ 4 ] =
, 3
.
, ,
.
, ,
. ,
unset($colors);
CofitfiufioeKa
,
, .
. . ,
.
. ,
,
s o r t ():
sort($_);
. , ,
. , $ s t r e e t s :
$streets[0] = ". ";
$streets[l] = ". ";
$streets[2] = "7- ";
sort($streets);
:
$streets[0] = "7- ";
$streets[lj = ". ";
$streets[2] = ". ";
s o r t () ,
, .
a s o r t ( ) :
asort($capitals);
,
. $ c a p i t a l s , :
$ c a p i t a l s [ ' ' ] = "";
$ c a p i t a l s [ ' T X ' ] = "";
$ c a p i t a l s [ ' O R ' ] = "";
6.
93
asort($capitals);
:
$ c a p i t a l s [ ' T X ' ] = ""
$ c a p i t a l s [ ' ' ] = ""
$ c a p i t a l s [ ' O R ' ] = ""
, 1. .
, . ,
$ c a p i t a l s [ 1 ] = "";
$ c a p i t a l s [ 2 ] = "",$ c a p i t a l s [ 3 ] = "";
a s o r t ()
$ c a p i t a l s [ 2 ] = ""
$ c a p i t a l s [ l ] = ""
$ c a p i t a l s [ 3 ] = ""
.
. . 6.1 .
6.1.
s o r t ($_)
, 1
a s o r t ($_)
r s o r t ($_)
a r s o r t ($_)
k s o r t ($_)
k r s o r t ($_)
u s o r t ($_,
_)
,
( 8)
n a t s o r t ($_)
( ) ;,
"" . ,
d a y l , d a y 5 , d a y l l , d a y 2 : d a y l ,
d a y 2 , d a y s , d a y l l .
s o r t () : d a y l , d a y l l , day2, day5
, . ; 1
.
, , , :
$CAcapital = $capitals[''];
echo $CAcapital,-
94
II.
,
:
$CAcapital = $ c a p i t a l s [ ' C A x ' ] ;
$ c a p i t a l s , :
Notice: Undefined index: CAx in d:\testarray.php on l i n e 9
(: : d:\testarray.php 9)
. $CAcapital ,
echo .
@:
@$CAcapital = $ c a p i t a l s [ ' ' ] ;
echo
echo
,
:
echo " { $ c a p i t a l s [ ' ' ] } " ;
:
l i s t
. l i s t () .
, ,
$shoeInfo = array("", "", 2 2 . 0 0 ) ;
, p r i n t _ r ():
print_r($shoeInfo) ;
:
Array
[0] =>
[1] =>
[2]
= > 22
)
l i s t :
l i s t ( $ f i r s t , $second) = $shoeInfo;
echo $second, " " , $ f i r s t ;
, $f i r s t $second,
$shoeInf , :
$ f i r s t = $shoelnfo[0] ;
$second = $ s h o e ! n f o [ l ] ;
6.
95
, $shoeInfo, ,
l i s t () . echo
, .
key (). ,
$ s h o e I n f o [ ' s t y l e ' ] = "";
echo
$shoeInf :
$value = $ s h o e I n f o [ ' s t y l e ' ] ;
$key = k e y ( $ s h o e I n f ) ;
echo "$key: $value";
:
$value "", key () $ .
, ,
, . ;
, .
/ /
.
, ,
6. ,
, .. , (traversing).
.
S .
,
*/ f oreach. ;
.
.
, .
, .
.
S c u r r e n t (%_). ,
.
/ n e x t ($_). .
S p r e v i o u s ($_). .
S end (%_). .
S r e s e t ($_). .
,
:
96
II.
$value = current($capitals);
echo "$value<br>";
$value = next($capitals);
echo "$value<br>";
$value = next($capitals);
echo "$value<br>";
,
.
, ,
r e s e t ():
reset($capitals);
echo ( 50
). .
.
. , ,
, next,
. , ,
, f reach,
. .
f o r e a c h
f o r e a c h
. :
foreach{$_ as $ => ^)
{
f o r e a c h .
S $_. .
f $. ,
. , ..
$.
J $. ,
.
, f o r e a c h
:
$ s t a t e _ p o p u l a t i o n = a r r a y ("CA" => 34501130,
"WY" => 494423,
"OR" => 3472867);
ksort($state_population);
f o r e a c h ( $ s t a t e _ p o p u l a t i o n as $ s t a t e => $population)
$population = number_format($population);
echo " $ s t a t e : $ p o p u l a t i o n . < b r > " ;
>
Web- :
: 34,501,130
OR: 3,472,867
WY: 494,423
6.
97
:
f o r e a c h ( $ s t a t e _ p o p u l a t i o n as $population)
(
) , .
f o r e a c h ,
.. r e s e t ( ) .
Onftec/ //
var_dump () p r i n t _ r () (. " ").
.
: count () s i z e o f ( ) . :
$n = count($_ );
$n = sizeof($_);
$
.
7Lfie6<$fia3oeanue &
anfioicu ( Haodofioifi)
.
, .
' \ ' .
foreach,
, . ,
.
,
$arrayname = explode("", );
, ]( . :
$ s t r i n g l = ":
";
$testarray = explode(":", $ s t r i n g l ) ;
print_r($testarray);
explode () $ s t r i n g l (:)
$ t e s t a r r a y , .
Array
(
[01 =>
[1] =>
[2] =>
)
$ s t r i n g l .
, .
$resString = implode("", $);
98
II.
$ r e s S t r i n g ,
$, . :
$ a r r a y l n = array("", "", "");
$stringOut = i m p l o d e ( " ; " , $ a r r a y l n ) ;
echo $ s t r i n g O u t ;
implode () $ s t r i n g O u t .
e x p l o d e (), implode ()
, . -
, .
:
;;
,
implode ( ) .
:
$stringOut = implode("; ", $ a r r a y I n ) ;
, :
; ;
^ [
( HaoJoftotn)
,
.
. ,
( 1) .
, f o r e a c h
.
.
e x t r a c t () compact ().
e x t r a c t ()
, . ,
.
, e x t r a c t () :
$testarray = array("pink" => "", "red" => "");
extract($testarray);
echo " $red.\n";
echo " $pink.";
:
.
.
compact ()
. .
:
$colorl = "";
$color2 = "";
$ = "";
$ = "";
6.
99
. , ,
, .
, .
,
. , , :
$subArray = a r r a y _ s l i c e ( $ , nl, 2) ;
nl ,
$ (0 , 1 ), 2
. :
$ t e s t a r r a y = array("", "", "", "");
$subArray = a r r a y _ s l i c e ( $ t e s t a r r a y , 1, 2 ) ;
$ subArray
[0] =>
[1] =>
$ t e s t a r r a y 1 .
0, 1,
" ", " ".
,
:
$bigArray = array_merge($2, %2,
100
...);
II.
:
$arrayl = array("", "");
$array2 = array("", "");
$bigArray = array_merge($arrayl, $array2);
$bigArray:
$bigArray[0]
$bigArray[1]
$bigArray[2]
$bigArray[3]
=
=
=
=
,
. , ,
. :
$ a r r a y l = a r r a y ( " c o l o r 1 " => "", "color2" => "");
$array2 = a r r a y ( " c o l o r l " => "", " c o l o r 3 " => "");
$bigArray = a r r a y _ m e r g e ( $ a r r a y l , $ a r r a y 2 ) ;
:
$ b i g A r r a y [ c o l o r l ] =
$bigArray[color2] =
$bigArray[color3] =
"$2^.
W^iL/
^"^
, a r r a y _ m e r g e _ r e c u r s i v e ( ) , array_merge ().
, .
" " .
, .
.
$diffArray = array_diff(%1, $2,
...);
a r r a y _ d i f f () $ d i f f Array
$ a r r a y l , $2.
. :
$arrayl = '" => "", "" => "", "" => "");
$array2 = array("", "", "");
$diffArray = array_diff($arrayl, $array2);
:
$diffArray[a] = ;
"" $ a r r a y l ,
$2, $dif f Array "".
a r r a y _ d i f f () . ,
$diffArray = a r r a y _ d i f f ( $ a r r a y 2 , $ a r r a y l ) ;
$dif f Array
$diffArray[0] = ;
, $2, $ a r r a y l ,
" ". $dif f Array.
6.
101
, , ,
:
$diffArray = array_diff_assoc($arrayl,
$array2);
a r r a y _ d i f f _ a s s o c () ,
, :
$ d i f f A r r a y [ a ] =
$ d i f f A r r a y [ b ] =
$ d i f f A r r a y [ ] =
$ a r r a y l $ 2 ,
.
, 1
$ s i m A r r a y = a r r a y _ i n t e r s e c t ( % 1 , $2,
...);
:
$simArray = a r r a y _ i n t e r s e c t ( $ a r r a y l , $ a r r a y 2 ) ;
$ s i m A r r a y :
$ s i m A r r a y [ b ] =
$ s i m A r r a y [ c ] =
a r r a y _ i n t e r s e c t ,
. , ,
a r r a y _ i n t e r s e c t _ a s s o c ( ) , :
$simArray = a r r a y _ i n t e r s e c t _ a s s o c ( $ a r r a y l , $ a r r a y 2 ) ;
$ s i m A r r a y $ a r r a y l
$ 2 , .
, , .
Dfiifiue /
.
S .
S
S .
$sum = a r r a y _ s u m ( $ a r r a y ) ;
:
$arrayAdd = a r r a y ( 3 , 3, 3 ) ;
$sum = a r r a y _ s u m ( $ a r r a y A d d ) ;
e c h o $sum;
9.
. , m a t e 5,
( "")
0.
102
II.
. ,
, .
,
$names = array("", "", "", "");
$names2 = array_unique($names);
$names2 :
$names2[0] =>
$names2[l] =>
$names2[3] =>
, .
( , ) .
, , :
$ t e s t a r r a y [ ' r o s e ' ] = red
$ t e s t a r r a y [ ' i r i s ' ] = purple
$arrayFlipped = a r r a y _ f l i p ( $ t e s t a r r a y ) ;
:
$testarray['red'] = rose
$testarray['purple'] = iris
. .
-.
. ,
, :
S
S
S
S
S
(onion) 0,50;
(apple) 2,50;
(orange) 2,00;
(bacon) 3,50;
(potato) 1,00;
(ham) 5,00.
:
$foodPrices['onion']
$foodPrices['apple']
$foodPrices['orange'3
$foodPrices['bacon']
= 0.50;
= 2.50;
= 2.00;
=3.50;
'
103
: (vegetable), (fiuit)
(meat).
, , .
, :
$ f o o d P r i c e s [ ' v e g e t a b l e ' ] [ ' o n i o n ' ] = 0.50;
$foodPrices [ ' v e g e t a b l e ' ] [ ' p o t a t o ' ] = 1.00;
$ f o o d P r i c e s [ ' f r u i t ' ] [ ' a p p l e ' ] = 2.50;
$ f o o d P r i c e s [ ' f r u i t ' ] [ ' o r a n g e ' ] = 2.00;
$ f o o d P r i c e s [ ' m e a t ' ] [ ' b a c o n ' ] = 3.50;
$ f o o d P r i c e s [ ' m e a t ' ] [ ' h a m ' ] = 5.00;
(multidimensional),
. . 6.1 $f o o d P r i c e s . ;;,
$f oodPrices -. > v e g e t a b l e , f r u i t meat . ,
meat -: bacon-3 . 5 0 ham-5 .00.
$foodPrices
vegetable
fruit
meat
onion
0,50
potato
1,00
orange
2,00
apple
2,50
bacon
3,50
ham
5,00
. 6. /. $foodPrices
$f o o d P r i c e s .
-, -, .
.
, .
, :
$ f o o d P r i c e s [ ' v e g e t a b l e ' ] [ ' p o t a t o ' ] = 1.00;
$ f o o d P r i c e s [ ' f r u i t ' ] [ ' a p p l e ' ] = 2.50;
:
t r a n s p o r t a t i o n [ ' c a r ' ] [ ] = "";
t r a n s p o r t a t i o n [ ' c a r ' ] [ ] = "";
, 0:
t r a n s p o r t a t i o n [ c a r ] [ 0 ] = ;
t r a n s p o r t a t i o n [ ] [ 1 ] = ;
a r r a y :
$foodPrices = array(
"vegetable" > array("potato" =>1.00, "onion" => .50),
"fruit" => array("apple" => 2.50, "orange" -> 2.00));
104
II.
, $foodPrices v e g e t a b l e f r u i t
array. ,
. :
$ f o o d P r i c e s [ v e g e t a b l e ] [ p o t a t o ] = 1.00
$ f o o d P r i c e s [ v e g e t a b l e ] [ o n i o n ] = .50
$ f o o d P r i c e s [ f r u i t ] [ a p p l e ] = 2.50
$ f o o d P r i c e s [ f r u i t ] [ o r a n g e ] = 2.00
, , p r i n t _ r () var_dump (). :
array(2) {
["vegetable"] =>
array(2){
["potato"] =>
float(l)
["onion"] =>
float(0.5)
}
[ " f r u i t " ] =>
array(2){
["apple"] =>
float(2.5)
["orange"] =>
float(2)
}
}
, .
v e g e t a b l e f l o a t p o t a t o
o n i o n 1 0 . 5 .
f r u i t .
, . ,
:
$hamPrice = $foodPrices['meat']['ham'];
echo:
echo $ f o o d P r i c e s [ ' m e a t ' ] [ ' h a m ' ] ;
,
. $ (
) :
echo " \ $ { $ f o o d P r i c e s [ ' m e a t ' ] [ ' h a m ' ] } " ;
, $ \ . ,
$ , .
:
$5
( ),
6.
105
.
, .
, . , ,
implode (), .
, . ,
, :
$resString = implode(":", $foodPrices['vegetable']);
$f o o d P r i c e s [ ' v e g e t a b l e ' ] ,
- ": ".
implode () , :
1: 0.5
1 0.5 $ f o o d P r i c e s [ ' v e g e t a b l e ' ]
p o t a t o onion , ,
implode ().
f oreach (
. ). , $f oodPrices,
, f oreach:
. ( (nesting).)
.
foreach ($foodPrices as $category )
{
:
onion: $0.50
p o t a t o : $1.00
a p p l e : $2.50
orange: $2.00
bacon: $3.50
ham: $5.00
, f oreach.
1. - $ f oodPrices,
$ c a t e g o r y ( ).
2. $ c a t e g o r y :
$f ood, $ p r i c e .
3. $ p r i c e .
4. .
5. $ c a t e g o r y .
6. $ p r i c e ,
.
106
II.
7. $ c a t e g o r y
f oreach.
8. $ f o o d P r i c e s
f oreach, $ c a t e g o r y .
9. 1-8 ,
$ c a t e g o r y . ,
f oreach.
, f o r e a c h
v e g e t a b l e -, $ c a t e g o r y .
, f o r e a c h
$ c a t e g o r y .
f oreach, -
$f o o d P r i c e s , .. .
, PHJ*
,
. .
, (,
) $_SERVER. ,
$_SERVER [' PHP_SELF' ] .
.
4.1.0 (superglobal)
(autoglobals),
, . (
8.) ,
$HTTP_SERVER_VARS, ,
( 8).
,
(_). ,
4.1.0 .
p h p . i n i , 5,
.
,
. php. i n i :
r e g i s t e r _ l o n g _ a r r a y s = On
On.
, Of f.
On,
, Off. , ,
, $HTTP_GET_VARS,
php. i n i ,
. Off, ,
.
6.
107
. 6.2.
. , , ,
10.
6.2.
$GLOBALS
. ,
$ t e s t v a r 1,
: $ G L O B A L S [ ' t e s t v a r ' ]
$_POST
, P O S , V
method = " p o s t "
$HTTP_POST_VARS
, $ _ P O S T
$_GET
, i
URL-, , ;.
GET: method = " g e t "
$HTTP_GET_VARS
, $_GET
$_COOKIE
cookie
$HTTP_COOKIE_VARS
, $_COOKIE
$_SESSION
$HTTP_SESSION_VARS
, $ _ S E S S I O N
$_REQUEST
, $ _ P O S T ,
$_FILES
$HTTP_FILES_VARS
, $ _ F I L E S
$_SERVER
. Web-
,
$HTTP_SERVER_VARS
, $_SERVER
$_ENV
: , ,
. ,
$HTTP_ENV_VARS
, $_ENV
$_GETH$SESSION
$_SERVER
$_ENV
$_SERVER $_ENV
. , ,
foreach($_SERVER a s $key => $value)
{
echo " = $key, = $ v a l u e \ n " ;
}
:
Kni04=DOCTJMENT_ROOT, =:/program f i l e s / a p a c h e
group/apache/htdocs
Knio4=PHP_SELF, 3Ha4eHHe=/test .php
108
II.
DOCUMENT_ROOT , Web-
Apache Web-. PHP_SELF
, .
$_ENV
phpinf () 16:
phpinf(16);
,
t r a c k - v a r s . 4.0.3,
, .
. , t r a c k - v a r s
, phpinf (). ,
, .
$argv $argc
.
.
Web , CLI .
, , , ,
. :
php add.php 2 3
add. php , 2 3 ,
. , $argv.
:
$argv[0] = add.php
$argv[l] = 2
$argv[2] = 3
, $argv ,
:
$sum = $argv[l]+$argv[2];
echo $sum;
5
$argc.
$argv. $argc 1,
. 3.
6.
109
III
PHP
&^ 9 ^, ^
< 6 ^,
3 /
! ,
,
. ,
. ,
-.
3 ...
>
>
>
>
>
i f
>
>
HP- .
, .
. ,
,
,
echo.
,
, .
// ,
/&
, , .
:
$ = " ";
echo $;
$ = " ";
echo $a; ,
,
, :
$ = " ";
echo $a;
$ " ";
echo $a;
,
, .. ,
. , :
i f ( )
{
$ = ;
echo $a;
}
or else if ( )
{
$a = ;
echo $a,}
,
, .
, .
S .
- .
, ,
, , . (conditional statement). .'HP
i f switch.
S . .
, .
, :
,
.
. , .[
, (loop).
for, w h i l e d o . . while.
: , .. , .
. , >,
. :
, . , -
, .
, .
Jlfioeefitca
(condition) , :
. , ,
.
. .
S ? , ?
15- ?
S ? , (>?
?
S ? ?
?
, .
. , ? ,
? , ?
114
III. P\
, (. 7.1).
7.1.
==
===
, ?
>
, ?
>=
, ?
<
, ?
<=
, ?
! =, < >
! ==
, .
, , ,
, , SS Sa.
, , "" .
, , .
ASCII-.
ASCII-, 0 127.
.
, , , 44, 46. ,
, "" .
.
V
/
f
$ == $
$ != 21
$ageNick < $ageBobby
$house_price >= 1000000
, ,
(==).
(=).
. , i f ($weather = "")
$weather "",
, .
: TRUE () FALSE ().
:
$ == $
, , $ = 1 $ = 1, , $ =
1 $ = 2 .
(!).
:
$ ! = 21
7.
115
, $ 21. <:,
, $ = 20, .
, ! .
, .
isset($_) #,
# .
empty($_) #,
# ,
# .
. , ,
,
is_int($number)
TRUE, $number
i n t e g e r . .
S i s _ a r r a y ($var2) , $var2 .
S i s _ f l o a t ($number) , $number
.
S i s _ n u l l ( $ v a r l ) , $ v a r l
S i s _ n u m e r i c ( $ s t r i n g ) , $ s t r i n g .
S i s _ s t r i n g ( $ s t r i n g ) , $ s t r i n g .
(!).
, TRUE,
:
! isset($_)
,
, . , ,
S .
. (regular expression).
, . ,
(*)
( d i r ex* . doc I s ex* . t x t ) . ex* . t x t ,
, exam, t x t , . t x t 4. t x t .
, , , .
, .
(), . ,
, ,
. ,
, .
, .
116
III. ]
() .
- . ,
26 .
. ,
. . 7.2
, .
7.2. ,
He
"
, 2
,
?
( )
g(er)m
,
g[er]m
g[Aer]m
,
, g [ a - c ] m
(
)
[ ]
[]
ger?m
germ, gem
geam
germ
Gem, grem
gem, grm
germ, g e l
gym, gum
gdm, gxm, g a l
bldg[l3] +
b l d g l l l , bldgl32
bldg, bldg555
ge*m
gm, g e e e m
germ, g r m
{}
ge{5}m
geeeeem
geeeem,
geeeeeem
in1,n2)
()
{2,5}
aa, a a a , a a a a ,
145aaaaa
1, a 3
g\*m
g*m
gem, g e r m
( | I )
(|)
. ,
(TRUE).
, .
7.
117
[--] .*
, , .
S
[--]. ,
( , ).
S .*. ,
.
: , .
, 123 ?, .
2
(|)
.
S . .
S ( | ). , .
(| )
.
, , .
3
[0-9]{5}(\-[0-9]{4))?$
.
S [ 0 - 9 ] {5}. , .
S \~. (\) , (-)
, .
S [ 0 - 9 ] {4}. , < [>.
/ ( ) ?.
, .
S $. ($) (..
).
90001 90002-4323.
, 9001 12-4321, .
4
.+@.+\.$
,
.com. , . .
S . +. ,
@.
S @. , ,
(\).
S .+. ,
.
118
III. PriP
S \ .. \ , (.)
.
S com$. ,
com.
you@yourcompany.com
j ohndoeSsomedomain.com.
, you@yourcompany. net, you@. com @you. com, .
e r e g ( ) .
:
ereg("",
);
, ,
, $name ( ) :
ereg(" [-- 1 - ] + $ " , $name)
.
/ $ .
, .
S
. , ,
.
(, -). ,
. , ,
, ..
, .
S "". ,
,
, .
. ,
, .
, .
. :
1 a n d | o r | 2 a n d | o r | a n d | o r | . . .
( ).
S and ( ). , .
S o r ( ). ,
.
*/ ( ). ,
, .
7.
119
. 7.3 , .
7.3.
, ...
$ageBobby == 2 1 o r $ageBobby == 22
21 22
29 ,
$ a g e S a l l y > 29 o r $ s t a t e == "OR"
29
$ c i t y
$ s t a t e OR,
, , 13
.
: , and, or.
, :
$resCity == "" or $ r e s S t a t e == "NV" and $name == ""
(NV),
. ,
, . , ,
.
.
1. , (and).
, $ r e s S t a t e $name NV
. , , or.
( ) .
2. , (or).
$ r e s C i t y . ,
, .
,
(()). , , . , :
($resCity == "" or $ r e s S t a t e == "NV") and $name == ""
, .. , (or). * ,
(NV). .
1. , (or).
, $ r e s C i t y $ r e s S t a t e
NV. ,
.
( ) .
2. , (and). PHP
$name. , ,
.
120
III.
,
. .
.
, , ,
, , | | (
or) && ( and).
^
"'
. , $ < $ && $ > $ $ < $b and
$ > $. | | or, && and.
onefiounofioe
(conditional statement)
. .
S if. , ,
.
S switch. ,
, .
i f
i f , ,
. i f :
if
()
elseif
{)
else
i f .
J if. , .
, .
i f .
e l s e i f e l s e , .
,
, e l s e i f , e l s e
, i f.
7.
121
/ e l s e i f . i f . e l s e i f .
.
, .
i f .
e l s e i f e l s e , .
,
i f (..
e l s e i f else), i f .
S e l s e . .
i f e l s e . e.'.se
, , ,
if, .
if. , .
, tio , :
i f ($score > 92)
$grade = "";
$message = "";
lseif ($score <= 92 and $score > 83)
$grade = "B";
$message = "";
elseif ($score <= 83 and $score > 74)
$grade = "C";
$message = "";
elseif ($score <= 74 and $score > 62)
$grade = "D";
$message = "";
lse
$grade = "F";
$message = " !";
echo $message. "\n";
echo " $grade\n";
i f .
1. $ s c o r e 92.
, $grade ,
$message , ,
echo. $ s c o r e
122
III.
2.
3.
4.
5.
$grade = "";
}
:
if ($grade > 92)
$grade = "";
.
, , .
if
,
, (!).
:
if ( ( " [ - ] * " , $ s t r i n g ) )
{
7.
123
if
(!("[-]*",
$string)
$ l i s t [ ] = $string."\n";
}
- (!)
$ l i s t , , , ..
, $ s t r i n g .
if
i f .
(nesting). , ,
, (Idaho, ID). ,
, , , , ;,
. if:
i f ( $ c u s t S t a t e == "ID")
{
if ($EmailAdd = "")
{
$contactMethod = " ";
}
else
{
$contactMethod = " ";
}
}
else
{
, . ,
. ,
$contactMethod ( )
, .
, .
switch
i f .
, . ,
, .
?
s w i t c h .
s w i t c h ,
, .
s w i t c h :
switch ($_)
{
case
:
;
break;
case
:
;
124
III. PhP
break;
default:
;
break;
}
s w i t c h PHP case,
, $_.
, break.
, ,
d e f a u l t . s w i t c h .
d e f a u l t , d e f a u l t
switch. .
,
:
switch ( $ c u s t S t a t e )
{
case "OR":
$salestaxrate = 0;
break;
case "CA":
$salestaxrate = 1.0;
break;
default:
$salestaxrate = . 5 ;
break;
}
$salestax = $orderTotalCost*$salestaxrate;
0%, 100%,
50%. s w i t c h
c a s e , ,
$ c u s t S t a t e . , $ s a l e s t a x r a t e
. , $ c u s t S t a t e ( ),
d e f a u l t $ s a l e s t a x r a t e
. 5. s w i t c h $ s a l e s t a x
(. 5) ( $ o r d e r T o t a l C o s t ) .
break,
c a s e . ,
break, switch.
case, .
c a s e s w i t c h break.
.
fljoefnofienue qeuctntfuu
.
, . , , 7.
125
echo, 50 ,
, , }
( ). .
/ for. ,
.
S whi 1. , >.
/ d o . . w h i l e . . :
,
.
.
f o r
f o r .
-,
. f o r
:
for (_;
_;
)
{
;
}
f o r .
S _.
-
. ,
$ i = l ,
$i, 1. 0 1.
, (, 2+2) .
S _.
. , .
, , $i<10,
, 10. $ i .
, $i<10 .
_
$ i < $ s i z e ; .
S . , ,
. , $i++;
$ i ( *) , $ i = + l ; $ i ; ,
f o r , $ i ,
. - $ i *
. , ,
! :
for ( $ i = l ; $i<=3; $i++)
{
126
III.
.
.
.
:
1. , !
2. , !
3. , !
for
f o r . , ,
1 9. ,
:
for ( $ i = l ; $i<=9; $i++)
{
echo "\ $i \n" ;
for($j=l; $j<=9; $j++)
{
$result = $i * $ j ;
echo "$i x $j = $result\n";
}
}
:
1
1x1 = 1
1x2 = 2
1x8 = 8
1x9 = 9
(
2
2x1 = 2
2x2 = 4
2 8 = 16
2 9 = 18
3
3x1 = 3
.
for
f o r
. f o r :
for ( ; ;
)
{
;
}
f o r .
7.
127
S , , .
, .
S 1 .
S .
,
.
(;). ,
, (,), ) .
:
$t = 0;
for ($i=0, $ j = l ; $t<=4; $i++, $j+ + )
{
$t = $i + $ j ;
echo "$t<br>";
}
$i=0, $ j = l , :
$t<=4, $i++, $j++.
:
1
3
5
.
1. . $ i :
0, $ j 1.
2. . $t 4?
, .
3. . $ t
$ i $ j (0+1 1) echo .
4. : $i++ $j-i+.
$ i $ j 1 2.
5. .
$ t 4? $ t 1,
.
6. . $ t
$ i $ j (1+2 3) echo .
7. : $i++ $j++.
$ i $ j 2 3.
8. .
$ t 4? $ t 3,
.
9. . $t
$i $ j (2+3 5) echo .
10. : $i++ $j++.
$ i $ j 3 4.
128
III.
11. .
$ t 4? $ t 5,
.
w h i l e
w h i l e ,
. .
1. .
2. .
3. , , .
w h i l e :
w h i l e (
)
{
;
}
w h i l e $ r u i t
:
$ f r u i t = a r r a y ( " " , "", "");
$ t e s t v a r = "";
$ = 0;
while ( $testvar != "" )
{
i f ( $ f r u i t [ $ k ] == "" )
{
$ t e s t v a r = "";
echo "\";
}
else
{
echo "$fruit[$k] - \";
}
$k++;
}
:
.
1. .
$ f r u i t , $ t e s t v a r
$, 0.
2. $ t e s t v a r != " " .
$ t e s t v a r ,
.
3. i f . , $ f r u i t [$k] == " " ?
$ 0,
$ f r u i t [ 0 ] . ,
, .. , if,
e l s e .
7.
129
4. , e l s e .
.
5. $ 1.
6. .
7. $ t e s t v a r != "".
$ t e s t v a r , ;.
8. if. , $ f r u i t [ $ k ]
==
""? $ 1
$ f r u i t [ l ] . ,
, .. , i : .
9. if. $ t e s t v a r
.
10. $ 2.
11. , .
12. $ t e s t v a r != "".
$ t e s t v a r ,
.
<**
while, , ..
. - , > , .. ,
. .
d o . . w h i l e
d o . . w h i l e w h i l e ,
. d o . . w h i l e
, .
do. . w h i l e :
do
{
;
}while ( ) ;
w h i l e d o . .while.
:
$ f r u i t = a r r a y ("", "", "");
$ t e s t v a r = "";
$ = 0;
do
{
if ($fruit[$k] == ""))
{
$testvar = "";
echo "\";
}
else
{
130
III.
$++;
}while ( $ t e s t v a r != " " ) ) ;
:
.. ,
w h i l e . w h i l e d o . . w h i l e
. w h i l e , ..
, . do. . w h i l e
. .
, , , w h i l e d o . . w h i l e ,
$ t e s t v a r :
$ t e s t v a r = "";
, . ,
w h i l e . d o . . w h i l e
, :
, d o . . w h i l e
. ,
.
, .
(infinite loop). - .
. ,
w h i l e .
, :
$fruit = array("", "", "");
$testvar = "";
while ( $testvar != "" )
{
$k = 0;
if ($fruit[$k] == "" )
{
$testvar = "";
echo "\";
}
else
{
echo "$fruit[$k] \";
}
$k++;
}
$ = 0;,
w h i l e . . :
7.
131
. $
( ), *
$ f r u i t [ 0 ] , , .. (
) , $ t e s t v a r 1
. , .
, .
. ,
, ,
.
S Web-. ,
. pai
30 , .
(Stop) , .
S PHP CLI. <Ctrl+C>. GTO
.
, .
, , .
(=) (==).
,
. :
while ($testvar = "")
$ t e s t v a r . ie
. , , :
while ($testvar == "")
$ t e s t v a r
. , .
, -. ,
$++;, $ 0
.
. \
.
" b r e a k .
V c o n t i n u e
, .
b r e a k c o n t i n u e . , b r e a k s w i t c h .
b r e a k c o n t i n u e .
break:
$counter = 0;
while ( $counter <5 )
132
III.
$counter++;
if ( $counter = = 3 , )
{
echo "break\n";
break;
}
echo " : =$\";
}
echo " \\";
:
: =1
: =2
break
, ,
break, w h i l e .
continue -.
continue.
$counter 0;
while ( $counter <5 )
{
$counter++;
if ($counter == 3 )
{
echo "continue\n";
continue;
}
b r e a k
c o n t i n u e .
. ,
(.. $ c o u n t e r 5).
b r e a k .
:
$test4infinity++;
if ($test4infinity >100 )
{
break;
}
, 100 ,
.
7.
133
3 / ...
>
>
>
>
^ . KS
, .
, .
, (
), , . .
.
S . ,
, ,
. - ,
, . .
*/ . , . , , g e t Data (), , , , ,
.
. -
, \
. !
, ,
. , ,
, ,
.
/
:
.
.
, ,
, . i n c l u d e .
,
, .
( ) ,
HTML . , .
. <img>
. :
define("HEIGHT", 60);
define("WIDTH", 60);
HTML-:
<img src="mypic.jpg" height="<?php echo HEIGHT?>"
width="<?php echo WIDTH?>" />;
,
.
, s i z e , i n c ( ),
, :
<?php
define("HEIGHT", 6 0 ) ;
define("WIDTH", 60);
?>
include("size.inc") ;
i n c l u d e , .. HTML-,
HEIGHT WIDTH, :
<img src="mypic.jpg" height="60" width="60" />
, Web- .
, HEIGHT
WIDTH. <img>
, , d i s p l a y P i x . inc,
. <1>- d i s p l a y P i x . inc,
s i z e . i n c ,
s i z e , i n c d i s p l a y P i x . i n c ,
displayPix.inc.
.
, ,
PHP-
. , ,
. , , ,
, .
8.
135
i n c l u d e ()
include_once("_") ;
,
. , i n c l u d e _ o n c e ()
(
) , .
r e q u i r e () r e q u i r e _ o n c e (),
i n c l u d e (), .
, , , .
r e q u i r e () .
i n c l u d e () ,
.
:
include("$filename");
, .
, .
, Sun. i n c :
echo " . . - .";
.
:
$today = dateC'D") ;
include("$today"."inc") ;
d a t e () (. 5) $ today
.
. , $today Sun (), ,
Sun. i n c .
Web- , >
. , . , :
http://yourdomain.com/secretpasswords.inc
, Web- s e c r e t p a s s w o r d . inc,
:
<?php
$mysecretaccount="account487 56";
$mypassword="secret" ;
?>
Web- PHP-
, ., .. s e
c r e t p a s s w o r d . i n c , HTML-.
.
.
S .php.
Web- ,
. .
136
III. -
,
. , ,
(, , ).
( )
. ,
. i n c ,
, .
S Web-
.php, , . i n c .
.
,
.
S , .
. ,
Web- .
, .
, ,
Web-. , Web- Apache
Web apache / h t d o c s (
h t t p d . conf).
, , d: \ i n c l u d e .
,
. ,
p h p . i n i (
, ). ,
i n c l u d e _ p a t h , .
, . :
include p a t h = " . ; d : \ i n c l u d e " ;
# Windows
include_path=".:/user/local/include";
# Unix/Linux/Mac
,
. ( ) ,
. ,
.
, i n c l u d e _ p a t h .
Windows Unix/Linux.
p h p . i n i ,
:
ini_set("include_path", "d:\hidden");
i n c l u d e _ p a t h
. Web-.
. :
include("secretpasswords.inc");
8.
137
, include_pcith
, (, ,
Web-), :
i n c l u d e ("d: / h i d d e n / s e c r e t p a s s w o r d s . inc") ;
.
^/
()
.
. (function) ,
.
, , Web-
:
echo '<img s r c = " g r e e n r u l e . j p g " width="100%" height="7" />
<address>Mofl
<br />. 1234
<br /> , 92126
</addressx/font>
<>
< =":1@."> </>
<img s r c = " g r e e n r u l e . j p g " width="100%" height="7" / > ' ;
Web- .
, add_f o o t e r (),
.
(.. ), :
add_footer()
.
,
.
(..
, ).
function _()
{
return;
}
, , ,
Web- ( ):
function add_footer()
{
138
III. PHf
8.
139
echo.
. , ,
. , : , !:
$ d i v i s i o n . ,
. $ d i v i s i o n
, $ d i v i s i o n .
(returning value). r e t u r n . ,
add_f o o t e r ()
. :
function a d d _ f o o t e r ( $ d i v i s i o n )
{
,
(local). . (
, (global),
g l o b a l . ) :
function format_name($first_name, $last_name)
{
".$first_name;
f ormat_name () , ,
$name:
format_name("",
echo "$name";
"");
, $name
.
.
140
III.
, .
:
function format_name($first_name, $last_name)
{
g l o b a l $name;
$name = $last_name.
",".$first_name;
$name :
format_name("", "");
echo "$name";
:
,
^
f/
,
- . , g l o b a l
$name,
, .. .
, ,
,
, .
:
$first_name = "";
$last_name = "";
function format_name()
{
global $first_name, $last_name;
$name = $last_name. ", ",$first_name;
echo "$name";
}
format_name();
$last_name $ i r s t _ n a m e
g l o b a l ,
. ,
$name (,).
format_name()
g l o b a l .
:
_(!,
2,
...);
, ,
. f u n c t i o n :
function _(1,
2,
...)
{
return;
}
, ( 9).
8.
141
s a l e s t a x f ) ,
. ( pa3f
), , ..
s a l e s t a x t ) : ( )
( ) . .
/ c o m p u t e _ s a l e s t a x ( 2 0 0 0 , "CA") ;
: 2000 ( ).
S t e _ s a l e s t (2*1000, "") ; 3Haie: 2000 "" ( ).
, .
S c o m p u t e _ s a l e s t a x ( 2 0 0 0 , "". "") ;
: 2000 "". "", .
. (
. 6.) :
function add_numbers($numbers)
{
for($i=0;$i
<sizeof($numbers);$i++)
.
, :
. s i z e o f ($numbers) ,
.
. ,
f o r :
if(!is_array($numbers)
{
, ,
, 5.
add_number ( ) :
$arrayofnumbers = a r r a y ( 1 0 0 , 2 0 0 ) ;
$ t o t a l = add_numbers($arrayofnumbers);
$ t o t a l 300.
, .
:
function functionx($x, $y, $z)
{
>
:
f u n c t i o n x ( $ v a r l , $var2, $ v a r 3 ) ;
: $
$ v a r l ; $ $var2 $z $var3.
142
III.
,
, . , ,
, :
function compute_salestax($orderCost, $ c u s t s t a t e )
{
)
, :
compute_salestax($custState, $orderCost);
,
(
). , .
0.
.
, NULL.
, . (
. 4.) :
Warning: Missing argument 2 for format_name() in t e s t i n g . p h p on l i n e 9
(: 2 format_name()
t e s t i n g . p h p 9)
, (warning) .
, f ormat_name (),
" " :
format_name("") ;
:
,
,
. .
, ,
(.. , ).
:
function add_2_numbers($numl=l, $num2=l)
{
$ t o t a l = $numl + $num2;
return $total;
}
,
.
add_2_number():
add_2_numbers(2, 2) ;
add_2numbers(2) ;
add_2numbers();
:
$total = 4
$total = 3
$total = 2
8.
143
( $ t o t a l = 4 ) ,
2. ( $ t o t a l = 3 ) 2 1, $2. ( $ t o t a l = 2 ) ,
1, $numl $num2.
,
. , , , :
function add_l($numl)
{
$numl = $numl + 1;
}
, . $num:.,
1. (.. ,
) . :
$orig_num = 3;
add_l($orig_num);
echo $orig_num;
3. add_l() *
$orig_num $numl. !
$orig_num . ,
:
r e t u r n $numl;
$orig_num add_l ():
$orig_num 3 ;
$orig_num = add_l($orig_num);
echo $orig_num;
4.
, $orig_name 1 :
. , , *
, ,
(passing by reference).
(&) :
function add_l(&$numl)
{
$numl = $numl + 1;
}
, ,
(.. $orig_num,
3). $numl $orig_num,
$numl , $orig_num.
, .
,
( ) . :
$orig_num = 3 ;
add_l (&$orig_num) ,echo $orig_num;
4.
144
III.
, ,
,
, .
r e t u r n .
.
r e t u r n
. :
r e t u r n ;
:
function add_2_numbers($numl, $num2)
{
$ t o t a l = $numl + $num2;
return $total;
}
. :
$sum add_2_numbers(5, ) ;
$ t o t a l , 11,
$sum.
, :
return $numl + $num2;
.
:
$ t o t a l _ h e i g h t = add_2_numbers($heightl, $ h e i g h t 2 ) ;
$ t o t a l S i z e $ c u r r e n t _ s i z e + add_2_numbers($sizel, $ s i z e 2 ) ;
if (add_2_numbers($costSocks, $costShoes) > 200.00 )
$echo "";
, r e t u r n
, , , . , ,
.
r e t u r n :
function f i n d _ v a l u e ( $ a r r a y , $value)
{
for($i=l;$i<sizeof($array);$i++)
{
i f ( $ a r r a y [ $ i ] = $value)
{
f i n d _ v a l u e ( ) , $ $value.
:
$names = array("", "", "");
find_value($names, "");
8.
145
.
, :
1.
, , ,
function is_over_100($number)
{
i f ( $ n u m b e r > 100)
{
r e t u r n TRUE;
}
else {
r e t u r n FALSE;
}
}
$number 100,
FALSE, TRUE.
,
FALSE :
function f i n d _ v a l u e ( $ a r r a y , $value)
{
for($i=l;$i<sizeof($array);$i++)
{
if($array[$i]
== $ v a l u e )
return
$i;
}
}
return FALSE;
}
, ,
FALSE.
,
.
. ,
.
,
, .
. , 7 , > . :
isset($varname)
empty($varname)
5 ,
. .
.
, .
, ,
. , . IKO
. :1
Web- (www. p h p . n e t / d o c s . php).
146
III.
OJfiadotfitca ouiurfoic
, .
, - - . ,
,
. ,
, .
FALSE.
, ,
.
, , .
d i e ( ) . :
die("");
d i e ()
. :
_()
or
die("");
FALSE, d i e ()
.
, MySQL:
mysql_connect("host", " u s e r " , "password")
or die(" . .);
. ,
.
,
(. 4). .
d i e () .
, FALSE. ,
d i e () .
,
. , ,
:
i f ( ! m y s q l _ c o n n e c t ( " h o s t " , " u s e r " , "password"))
{
8.
147
-
> ...
>
>
>
>
. , \ ^ 4, - .
5 -
, , .
.
Zend 2, 5 4.
, 5 , - -.
/ -^/
-
. .
- ,
. -
Java C++.
-
, .
. , , ;
, :
, , .. ,
.
-
(object). ,
. ,
, , ,
. ,
.
- ,
.
- .
- (object).
. ,
( ), , ,
. , ,
, , .
.
, , , , , , , ,
. .
, . ,
, .
, , , , ,
, , , , , ..
, (class) (),
. , ,
. , ,
, .
( ).
, , .
- , .
, , .
, ,
. , , ,
. , ,
.
. , ,
( ) , .
(property), (attribute).
, . ,
, , .
. ,
, $color. ""
$color ($color = ).
, ,
. .
, , -.
, ,
(responsibility). , "" ,
. (),
, (method).
9. -
149
PHP , . ,
.
.
.
, , , parkCar () g e t C o l o r ( ) .
,
.
.
() .
. ,
, ; ^
. ,
. , (house) ( )
( f r o n t door). (neighbor)
. , house
(openFrontDoor), .
. f r o n t cloor
( house) openDoor ( ) .
" ".
, . 1
. , "" ""
, ,
, , , .. ,
"" . ,
.
.
(inheritance). >,
, , ,
. : redRose ( ) whiteRose (61
). ,
, . ieo .
Rose.
, $ p l a n t = bush ( ), $stem = t h o r n s (.
), $blooms = June ( ).
. Rose (master chss),
win (parent class). , redRose whiteRose
(subclass), (child class), (child),
.
- .
, ( $ c o l o r = )
whiteRose ( $ c o l o r = ) redRose.
, -, ,
. - .
.
150
III.
- 5
- , ,
, , .
, , 4,
5. - .
S (polymorphism).
, .
, .
,
().
s w i t c h .
S (multiple inheritance).
.
.
nfioificuui
-
, ,
. ,
.
.
.
. ,
.
. , .
,
. ,
, , , , , ,
, , , , , , ..
?
? , .
.
(.. )
. .
.
,
, .
, ,
. ,
, .
9. -
151
. , . ,
, , , ,
, ..
,
, .
" ". (.. ).
openBankAccount ().
: , ,
.
, -
- . ,
. ,
?
. .
1. c l a s s . c l a s s
. .
2. c l a s s ,
. .
c l a s s ,
i n c l u d e .
3. . ,
.. (instantiation).
4. .
. ,
.
.
Onfieqejietiue
,
. () .
c l a s s
:
c l a s s
{
}
152
III.
,
s t d C l a s s .
. ,
,
c l a s s whiteRose extends Rose
{
, ,
whiteRose, Rose. Rose
-.
,
. ,
" ".
.
c l a s s Car
{
var $color;
var $tires;
var $gas;
}
. ,
, , .
, .
. , .
.
.
.
S :
var $color = "";
var $gas = 10;
var $tires = 4;
S :
var $color = ""." ";
var $gas = 10-3;
var $tires = 2*2;
,
.
var $doors = array(" ", " " ) ;
, ( , "
") , .
9. -
153
$ t h i s
$ t h i s "
. . :
.
$ t h i s :
$ t h i s->_
, $gas
$this->gas
, $ t h i s $gas
, , , :
$ t h i s - > g a s = 20;
i f ( $ t h i s - > g a s > 10)
$product[$this->size] = $price
, $.1->_ : , $_ .
, $ t h i s ,
gas. $ t h i s - > $ g a s , . ( , ) ,
$gas .
,
. , "" ,
. $gas,
,
. ,
$amount ( ).
c l a s s Car
{
var $gas = 0;
function addGas($amount)
{
$this->gas = $this->gas + $amount;
echo " $amount ";
>
}
addGas () , ;
, .
,
( ). : c o n s t r u c t ,
d e s t r u c t c l o n e . :, .
(constructor) ,
. ,
- .
.
154
III.
( c o n s t r u c t ) ,
, .
:
funct i on
cons t r u e t ( )
{
$this->gas = 1 0 ;
#
$this->openDoor();
}
(.. ) .
d?P?~$tb_ 5 . , Mifexrj , 5.
. ^ 0 3 5 4SS&P^ c o n s t r u c t ( ) . ,
, .
, .
, . -
, .
,
. :
class MessageHandler
{
var $message = " ";
function
construct($message)
{
$this->message = $message;
}
function displayMessage()
{
echo $this->message. "\n";
}
}
MessageHandler $message, ,
displayMessage, .
, ,
, . :
c l a s s MessageHandler
{
var $message = " ";
function
construct($message)
$this->message = $message;
function displayMessage()
echo $this->message. "\n";
function lowerCaseMessage()
$this->message = strtolower($this->message);
$this->displayMessage() ;
}
9. -
155
lowerCaseMessage ( ) .
, lowerCaseMessage ()
. , , .
.
9.1 ,
HTML-. " .
9.1. ,
<?php
/* : form
* :
, HTML-
*
. 3 .
*/
class Form
t
var $fields=array(); #
var $processor;
#
var $submit = " "; # Submit
var $Nfields = 0 ;
#
/* :
* ($processor) .
*/
function
construct($processor, $submit)
{
$this->processor = $processor;
$this->submit = $submit;
}
/* .
*/
function displayForm()
{
echo "<form action='{$this->processor}' method='post'>";
echo "<table width='100%'>";
for($j=l;$j<=sizeof($this->fields);$j++)
{
echo "<trxtd align=\"right\">
{$this->fields[$j-l]['label']}: </td>\n";
echo "<td>
<input type='text'
name='{$this->fields[$j-l]['name']}'>
</tdx/tr>\n";
}
echo "<tr><td colspan=2 align='center'>
<input type='submit'
value= ' {$this->submit} ' ></tdx/tr>\n" ;
echo "</table>";
/* .
* .
*/
function addField($name, $label)
{
$this->fields[$this->Nfields]['name'] = $name;
156
III.
PHP
c o n s t r u c t ( ) . ,
$ p r o c e s s o r $ s u b m i t , .
f a d d F i e l d ( ) . $f i e l d s . ,
,
:
$fields[l][name]=first_name
$ f i e l d s [ l ] [ l a b e l ] = F i r s t Name
$fields[2][name]=last_name
$ f i e l d s [ 2 ] [ l a b e l ] = L a s t Name
..
S
d i s p l a y F o r m ( ) . , ..
HTML, .
, .
,
Form, 9.1.
, , - .
i n c l u d e ()
.
, .
, .
(instantiation). ,
, - ,
. :
$_ = new (,
, . . . ) ;
$ J o e = new
$car_Joe =
$car_Sam =
$customerl
Person("");
new C a r ( " " ) ;
new C a r ( " " ) ;
= new C u s t o m e r ( " " ,
"",
$custID);
9. - PHP
157
,
.
:
$Joe->goToWork();
$car_Joe->park("");
$car_Sam->paintCar("") ;
$name = $customerl->getName () ,-
, , .
, ,
. ,
( ).
9.2 Form,
9.1.
9.2. Form
< ?php
/* : buildForm
* :
Form
*
HTML-.
*/
require_on.ce (" form, inc") ;
echo "<htmlxheadxtitle>OopMa
HOMepa</titlex/head><body>" ;
$phone_form = new Form("process.php", " ");
$phone_form->addField("first_name", "");
$phone_form->addField("last_name", "");
$phone_form->addField("phone", " ");
echo "<>, :</h3>";
$phone_form->displayForm();
echo "</bodyx/html>" ;
?>
r e q u i r e _ o n c e ( ) form, i n c
Form . $phone_f orm. 3aieM
, . ,
,
d i s p l a y F o r m ( ) .
Form
(. 9.1).
CtcfiMffibie (
(public),
(private). , .. ,
, . ,
:
class Car
{
var $gas = 0;
function addGas($amount)
158
III. PHP
[]
[ i
' ^
>"> &
- u fp
; ! j | http://localhost/test/buildForm.php
v : Q
, :
:
:
:
. 9.1. , 9.2
$gas -
:
$mycar = new Car;
$gas_amount = $mycar->gas;
$gas_amount
$gas mycar. :
$mycar->gas = 20;
.
. addGas ()
"" (.. $gas):
$new_car = new Car;
$new_car->addGas(5);
PHP .
.
| S p r i v a t e ()
- , .
9. -
159
S p r o t e c t e d ()
-. El
.
,
private $gas = 0;
!
:
F a t a l e r r o r : Cannot access p r i v a t e p r o p e r t y c a r : : $ g a s in
c : \ t e s t c l a s s . p h p on l i n e 17
( :
c a r : : $ g a s c : \ t e s t c l a s s . p h p 17)
$gas
addGas (), , ,
.
, (private)
(protected). addGas () . .
, , !,
(, ).
:
c l a s s Car
{
private $gas = 0;
private function addGas($amount)
{
$this->gas = $this->gas + $amount;
echo " $amount ";
}
function buyGas($amount)
{
$this->addGas($amount);
}
>
$gas
(.. ) buyGas ( ) . ,
addGas ( ) . addGas ()
.
$new_car = new Car;
$new_car->addGas(5);
, buyGas ():
$new_car = new Car;
$new_car->buyGas(5);
:
5
. ( p r i v a t e ) ,
( , ) p u b l i c .
. , . ,
160
III.
p u b l i c $gas = 0;
var $gas = 0;
E x c e p t i o n ().
,
. ,
. -
.
,
(.. $gas>0). ,
$gas . .
E x c e p t i o n :
$ t h i s - > g a s = $ t h i s - > g a s - 5;
try
{
if
( $ t h i s - > g a s < 0)
t r y c a t c h .
S t r y .
TRUE, , ..
Exception. , ,
.
S c a t c h , $.
. ,
getMesssage () Exception.
, Exception,
echo.
, c a t c h ,
.
c l o n e ()
( ). .
9. -
161
(.. ) c l o n e ()
.
c l o n e ():
c l a s s Car
{
private $gas = 0;
private $color = "";
func t i on addGa s($ amoun t)
{
$this->gas = $this->gas + $amount;
echo " $amount ";
}
function
clone()
{
$this->gas = 0;
}
}
, , :
$firstCar = new Car;
$firstCar->addGas(10);
$secondCar=$firstCar->
clone();
.
S $ f i r s t C a r . 10 ,
addGas ( ) .
S $secondCar. , 0
. $secondCar $f i r s t C a r
c l o n e (), $gas
0 ($color).
clone (),
, $f i r s t C a r $secondCar, ..
$secondCar, $f i r s t C a r , 10
:
unset($objName);
, , .
$myCar = new Car;
unset($myCar);
u n s e t () .
d e s t r u c t (),
. , .
class Bridge
{
function
destruct()
{
echo. " ";
162
III.
}
}
Bridge,
$bigBridge = new Bridge;
unset($bigBridge);
d e s t r u c t () u n s e t ().
d e s t r u c t () .
, c o n s t r u c t () c l o n e (),
. ,
.
9. -
163
IV
5?
IV , ,
. ,
, Web-,
,
.
,
HTML-,
,
Web-.
10
Web-
/
>
>
>
>
...
Web-
HTML-
,
Web-
. .
- Web. (static) Web-
. ,
(dynamic) .
. ,
Web-,
. ""
, .
.
Web-
HTML-. , , ,
Web-.
(
12) .
HTML,
. , . (
, HTML 4 "", 3- ,
"".)
Web-
.
Web-t/
Web- . Web ,
. Web-
, .
,
, . ,
.
S ,
,
S , Web-. Web- ,
.
S , , Web- , .
, ,
Web-. ,
.
. Web-, , .
</ , Web. .
S .
,
. ,
Web.
S .
,
.
S Web-
. , ,
, .
.
,
Web-
Web-
, . , , . ,
/ , ..
Web-
.
, Web , Web-.
, Web-, .
, Web-, ,
Web-.
. , ,
Web-, .
, .
168
IV. -
, URL-
, , . Web ,
( i n d e x . html), .
, . Web ,
.
Forbidden
<D
Web- . ,
.
,
Internet.
() .
.
( ) .
HTML (, < s c r i p t > ) ,
Web- .
,
, ,
( ) Web-. ,
, , " ".
Web-
Web- .
Web- (),
, Internet -
. Web- .
,
10. Web-
169
. Web- .
Web- .SSL
(Secure Sockets Layer).
Web. . , Web-
, .
SSL URL-
h t t p s , h t t p .
Web- -. ,
SSL,
. , Apache ;
Web-: www.modssl.org w w w . a p a c h e - s s l . o r g .
Web- IIS Microsoft, SSL
Web- www.microsoft. com.
Gfflo^ficufceHue / Web-ctnfiaH
Web-. Web-)
,
. Web- ;
.
Web-,
. HTML- echo.
HTML,
, :
include("_") ;
- Web- !
, . <}
(<?php ?>), echo
HTML .
IPaJoina -/
Web- ,
. HTML-.
,
.
. , , ,
,
(, ). ,
.
HTML-
Web-. , .
, ,
.
170
IV. -
Web-. .
HTML MySQL,
& MySQL For Dummies
Wiley Publishing, b e , .
Web-
Web- HTML.
HTML, ,
HTML 4 "", 3- , "".
HTML-
.
S HTML- echo,
:
echo "<form a c t i o n = ' p r o c e s s f o r m . p h p ' method='POST'>\n
< i n p u t t y p e = ' t e x t ' name='name'>\n
< i n p u t t y p e = ' s u b m i t ' value=' '>\n
</form>\n";
S HTML .
.
, :
<?php
?>
171
Q - 0
[- | [ | | |
0 0*
: [) http://localhost/test/SimpleForm,php
*
v j Q
***J
)j
.;
. /0./. , HTML
<input t y p e = " t e x t " name="fieldname" value="">
, , < .
, , . , , . , , , . ,
.
:
<input t y p e = " t e x t " name= "country" value="CIHA">'
*
. , (, ),
. ,
.
. -, ( :
, 12) . ;;
.
, HTML <input>:
<input t y p e = " t e x t " name="phone" value="<?php echo $phone ?>">
HTML echo:
echo "<input t y p e = ' t e x t ' name='phone' v a l u e = ' $ p h o n e ' > " ;
,
, .
.
10.1 .
. 10.2.
172
IV. -
ge
'
: i f j | http://tacalhos4test/dlsplayForm.php
g j
, .
: [
: |
: [
: | . 1234
: |
:
: [88888
VJ.
jQroToeS:
| -
. 10.2.
10.1. HTML-
<?php
displayForm
/* :
* :
*
.
*/
echo "<html>
<head><title>Aflpec oyae</title></head>
<body>";
$customer = array("firstName"=>"",
"1"=>"",
"lastName"=>"CMHT",
"street"=>". 1234",
"1"=>" ",
"state"=>"ID",
"zip"=>"88888");
$labels = array("firstName"=>":",
"midName"=>"BTopoe :",
"las tName"= >":",
"street"=>":",
"city"=>"ropofl:",
"state"=>"IUTaT:",
11
10.
Web-
173
{$customer['lastName']}</h2>\n";
echo "<p align='center'>
<b> , '
.</>
<hr>
<form action='processform.php' method='POST'>
<table width='95%' border='0' cellspacing='0'
cellpadding='2'>\n";
foreach($customer as $field=>$value)
{
echo "<tr>
echo "</table>
<div a l i g n = ' c e n t e r ' > < p > < i n p u t t y p e = ' s u b m i t '
' > < / p x / d i v >
</form>";
?>
< / b o d y x /html>
value='
10.1 ( displayForm.php)
S $customer, . 13 , .
S $ l a b e l s .
S
processform.php.
S HTML. >IM
HTML. HTML
, HTML 4
"", 3- , "".
S $customer
f oreach.
$ f i e l d .
maxlength, ,
.
.
,
maxlength.
,
HTML-, ,
, .
HTML, -
774
IV. -
echo.
.
echo " < s e l e c t name='dinner' >
<option>$dinnerl</option>
<option>$dinner2</option>
</select>",-
. , $ d i n n e r l ,
$dinner2 .
.
. ,
:
echo "<input t y p e = ' r a d i o ' name='dinner'
value='$dinnerl'>$dinnerl
<input t y p e = ' r a d i o ' name='dinner'
value='$dinner2'>$dinner2" ;
. ,
name <input> .
echo "<input type='checkbox' n a m e = ' d i n n e r [ ] '
value='$dinnerl'>$dinnerl
cinput type= ' checkbox' n a m e = ' d i n n e r [ ] '
value='$dinner2'>$dinner2";
$dinner.
, :
$dinner[0]=
$dinner[1]=
10.2 Web-,
. .
<?php
/* :
displayDate
* :
,
*
, .
*
.
*/
echo "<html>
<headxtitle>flaTa</titlex/head>
<body>";
/* ,
* , - .
*/
$monthName = array(l=> "", "", "",
"", "", "",
"", "", "",
"", "", "");
$today = Time (),- #
echo "<div align='center'><> :</>
<form action='processform.php' method='POST'>\n";
/* */
$todayMO = dateC'm", $today); $today
echo "<select name='dateMO1>\n";
10. Web-
175
$monthName,
, . $ today
.
,1
: , .
$monthName. 1;.
,
. .
. ^
.
. 10.3 , 10.2,
176
IV. -
'
IS
,!
**5
"* 1
V J &h
'
: j j g | http://localhost/test/selectDate.php
* mm* :u3mi
\ ^
>"; 19 2005
<
. 10.3.
a c t i o n <f orm> ,
: a c t i o n = " _". , 10.1 10.2
a c t i o n = " p r o c e s s f o r m . p h p " .
, a c t i o n .
6,
. POST,
$_POST, GET $_GET.
$_REQUEST.
, .
, POST,
:
echo "<input t y p e = ' t e x t ' name='firstName'>";
f irstName,
$_POST[ ' f i r s t N a m e ' ] .
,
. ,
. $_POST
(.. $_POST ). ,
, (. ),
:
$_POST['dinner'][0] =
$_POST['dinner'][1] =
10. Web-
177
10.3 ,
. 10.2.
10.3.
<?
/*
Script name:
* Description:
displayFormFields
, ,
.
*/
echo "<html>
<headxtitle>Aflpec oyae</title></head>
<body>";
foreach ($_POST as $field => $value)
{
echo "$field = $value<br>";
}
?>
</bodyx/html>
POST GET
; P O S T G E T .
, , , ,
-.
V G E T . UR. , ,
processform.php?lname=Smith&fname=Goliath
. G E T
,
, .
/
P O S T . P O S T < j
. ;
. "
.
CGI-, ,
. G E T .
. :?
. , G E T P O S T .
P O S T ( ) ;
.
,
. 10.2. d i s p l a y F o r m . p h p (. 10.1) \
a c t i o n <form> a c t i o n = " d i s p l a y F o r m F i e l d s . p h p " .
d i s p l a y F o i m F i e l d s . p h p (. 10.3), Web-
:
firstName =
lastName =
street = . 1234
178
IV. -
city =
state = ID
zip = 88888
10.3 ,
, . 10.2.
,
.
,
, , .
, , ,
, ,
Web-. ,
. .
(validating information), ,
.
S . ,
,
. ,
,
.
S .
, .
, . ,
,
,
. , &*
.
, ,
empty () :
empty($_POST[_]);
, :
i f(empty($_POST['_']))
{
.
, (zip) 8899776,
. ( )
zip+4 (.. ).
, Web- ,
. , HTML,
10. Web-
179
. ( < s c r i p t > . )
, , .
.
,
. ,
.
, , , 555-5555 (888) 555-5555,
. 14 , . , ,
. , : ,
.
, 7.
. ,
, .
,
. , (
), ('), (-) ( ). , , 50 .
:
$last_name = t r i m ( $ _ P O S T [ ' l a s t _ n a m e ' ] ) ;
if ( !ereg("[---Za-z' - ] { 1 , 5 0 } " , $last_name))
{
t r i m ( ) .
( ) if.
! : ,
.
,
([ ]), (-),
, . (..
) ci ie , .
, 1
10.4 ,
. .
, >ix
. ,
. ,
.
180
IV. -
10.4 . .
,
( 10.5). ( 10.6).
10.4, ,
<?php
/* :
validateForm
* :
*
.
*/
include("info.inc");
#6
########################
## ##
########################
if(!isset($_POST['Submit']))
#10
{
include("addressForm.inc");
}
########################################################
## , .
##
##
##
## .
##
## ,
##
## .
##
## .
##
########################################################
else
#21
{
foreach($_POST as $field=>$value)
#23
{
if(empty($_POST[$field]))
#25
{
if($field != "midName")
{
$blanks[$field] = "blank";
#29
}
}
else
#33
{
$value = trim($value);
if($field != "zipcode")
{
if (!("[-----9' .-] {1,65}$*-, $value) )
{
$formats[$field] = "bad";
}
}
elseif($field == "zipcode")
{
if(!("[0-9]{5}(\-[0-9]{4})?", $value))
{
$formats[$field] = "bad";
}
}
}
}
#51
10. Web-
181
### , ###
### ###
###
###
if (@sizeof($blanks) > 0 or @sizeof($formats) > 0)#54
{
if (Osizeof($blanks) > 0)
{
echo "<>
.
: </bxbr>";
foreach($blanks as $field => $value)
{
echo " {$labels[$field]}<br>";
}
}
if (@sizeof($formats) > 0)
{
echo "<b>B
.
:
</b><br>";
foreach($formats as $field => $value)
{
echo " {$labels[$field]}<br>";
}
}
echo "<hr>";
include("addressForm.inc");
}
else
#78
{
### , ###
###
.
###
echo "<htmlxhead><title>MMH
</titlex/headxbody>\n" ;
foreach($_POST as $field=>$value)
{
if($field != "Submit")
{
echo "</bodyx/html>" ;
}
}
?>
10.4 ,
.
S 6. i n f o . i n c ,
$ l a b e l s , .
10.5. (
. 8.)
S
182
10. i f , $_POST
Submit. , ,
IV. -
, Submit.
$_POST
. if.
(.. Submit ),
, addressForm. i n c (.
10.6), . i f
,
.
/ 21. else- (..
$_POST Submit).
.
S 23. f o r e a c h
$_POST.
25. i f
. ,
33, .
29. $ b l a n k s ,
( ,
, , ).
S 33. e l s e ,
, . ,
, .
, , , , .
,
. ,
- ,
$f ormats.
S 51.
. , $ b l a n k s
$ formats,
. , $blanks
$ formats .
S 54. i f ,
- .
, $blanks $ormats.
,
.
S 78. e l s e ,
.
, .
, 10.4
, (
33-50). .
.
10. Web-
183
10.5 ,
10.4. ,
.
<?php
/* :
info.inc
* :
*
.
*/
$label's = array( "f irstName"=>"MMfl: ",
"midName"=>" :",
"lastName"=>":",
"street"=>":OiHua: " ,
"city"=>"ropofl:",
"state"=>"lIlTaT:",
"z ipcode"=>" : " ) ;
?>
10.6 ,
. 10.1,
, . 10.2.
< ?php
/* :
addressForm.inc
* :
.
*/
echo "<html>
<headxtitle>Aflpec *;/titlex/head>
<body>";
echo "<p align='center'>
<form action='validateForm.php' method='POST'>
<table width='95%' border='0' cellspacing='0'
cellpadding='2'>\n";
foreach($labels as $field=>$value)
{
if(isset($_POST[$field]))
#13
{
$value = $_POST[$field];
}
else
{
$value = "";
}
echo "<trxtd align= ' right' >{$labels [$field] }</brx/td>
<tdxinput type= ' text' name='$field' size='65'
maxlength='65'
value='$value'> </td> </tr>";
}
echo " </table>
<div align='center'>
<pxinput type='Submit' name= ' Submit'
184
IV. -
, Submit:
< p x i n p u t type= ' Submit' name= ' Submit'
value= ' ' > < / p x / d i v >
v a l u e $_POST.
, ,
, , .
i f :
if($_POST['Submit']
== " ").
. 10.4 ,
. Web-
. ,
.
. :
:
. . :
:
:[
: |
: [
: ( 1234
: [^
: [~
: 888-88
* |
. 10.4. , ,
10. Web-
185
,
() .
(, )
.
, HTML-. , ; .
,
. , 1 < s c r i p t > . ,
, , : Web-.
.
S s t r i p _ t a g s ( ) . ,
, .
S h t m l s p e c i a l c h a r s ( ) .
HTML .
. :
< <
> >
& &.
1
. ,
$last_name = strip_tags($last_name);
s t r i p _ t a g s ( )
$last_name < , > \
. , :
$last_name = s t r i p _ t a g s ($last_name, " < b x i > " ) ;
$last_name , <> <i>.
< > ,
. , HTML.
h t m l s p e c i a l c h a r s ():
$message = h t m l s p e c i a l c h a r s ( $ m e s s a g e ) ;
, s t r i p _ t a g s ()
h t m l s p e c i a l c h a r s (). $message,
:
<?php ?> .
s t r i p _ t a g s ():
$message = strip_tags($message);
echo $message;
:
186
IV. -
h t m l s p e cialchars():
$message = h t m l s p e c i a l c h a r s ( $ m e s s a g e ) ;
echo $message;
:
<?php ?> .
:
<?php ?> .
.. . , < >
, .
t r i m ( ) .
. ,
.
t r i m (), :
$last_name = t r i m ( $ l a s t _ n a m e ) ;
10. Web-
187
11
Web-
/ ...
>
>
>
>
>
cookie
HTML-
JavaScript
Web- V** , , :.
( 10.) Web-
. , ""
, , ,
, ,
. ,
. , Web- >
, .
,
Web-.
Web-cinfiaHUk,
Web- .
, Web- .
. Web-
. Web-,
, .
Web- .
, , .
.
^ [ Web-t/cua
Web- . , Web-^
(
), . , . Web- i :epe ,
.
f . , .
/ .
Submit.
S . h e a d e r ( ) ,
- .
.
echo HTML
( , HTML).
:
echo "<a href='newpage.php';> </>";
(. 10).
<form> , ,
. Submit
Web-.
,
. ,
. ,
Cancel () Next () <form>
<input>. ,
a c t i o n <f orm>.
: ,
,
Web-. h e a d e r { ) , s e t c o o k i e ( ) s e s s i o n ( ) .
, :
<html>
<head><title>TecTMpoBaHne header()</title></head>
:<body>
<?php
header("Location: http://janetscompany.com");
?>'
</bodyx/html>
, h e a d e r ( ) HTML.
, .
11. Web-
189
HTML PHP, ,
.
<?php
header("Location: http://janetscompany.com");
. ?>
<html>
: <head><title>TecTMppBaHMe header()</title></head>
<body>
</body>
j. </html>
; :
| <?php
header("Location:
http://company.com");
I ?>
i <html>
I <head><title>TecTHpoBaHHe header()</titlex/head>
[ <body>
</body^</html>
|
!
i
[
!
. ;
< ? p h p . .
Web-, , , h e a d e r ( ) ( .
). , j
.
,
.
h e a d e r () :
h e a d e r ( " L o c a t i o n : URL");
Web- L o c a t i o n :
URL. , URL-.
h e a d e r ( ) .
h e a d e r ( " L o c a t i o n : newpage.php");
header("Location: http://company.com/catalog/catalog.php");
, h e a d e r () :
- .
HTML, -
h e a d e r ( ) . s e t c o o k i e O s e s s i o n ()
(. ", ").
, , h e a d e r ()
.
. , h e a d e r ()
. :
<?php
if ($typeAcct == "admin")
{
header("Location: AdminPage.php");
}
else
{
190
IV. PHP-
header("Location:
SiteHomePage.php");
?>
, Web-.
h e a d e r () ,
HTML- Web-.
h e a d e r () - HTML- .
71/1 / / /
Web-
, , ,
.
.
S URL-.
URL- .
.
S cookie.
cookie,
"-" (_=).
, ..
. cookie
, Web-.
cookie .
/ HTML-.
Web-
HTML-. Submit
.
, .
*/ . 4,
.
(Web-).
Web-.
.
URL-
URL-.
:
^
( $),
. = URL
?. :
11. Web-
191
$_REQUEST. :
echo "{$_REQUEST['city']}, {$_REQUEST['state']};
URL .
, (
), .
</ . URL
. ,
. , ,
URL-.
S URL- .
, Web- .
URL- a u t h = y e s (
, ).
$_GET[' a u t h 1 ] =yes
.
. 6payjepa
URL- h t t p : //www.-, c o m / p a g e . p h p ? a u t h = y e s
-
.
S URL .
URL-,
.
S URL.
URL- ( ).
,
, URL, .
192
IV. -
cookie
, ,
cookie. "-"
(=) , URL-.
cookie ,
.
, cookie ,
() Web-.
. cookie
, Web-.
, , . , (
) cookie .
, .
Web- .
, - .
.
cookie. Web- cookie
, .
cookie
. cookie ,
Web-.
cookies , ,
. .
S cookie.
,
cookie (
),
Web-.
S .
4 ,
(session)
, , Web-.
, .
S .
, , ,
, cookie.
.
cookie
cookie, s e t c o o k i e (), :
setcookie("",
"");
( $),
. ,
Web-. , cookie
state=CA:
s e t c o o k i e ( " s t a t e " , "");
11. Web-
193
cookie $_1.
,
e c h o " { $ _ C O O K I E [ ' s t a t e ' ] } " ;
:
, cookie ,
.
.
cookie
cookie. s e t c o o k i e ()
setcookie("", "",
-);
-
, cookie
. t i m e () m k t i m e ( ) .
S t i m e ( ) . .
cookie t i m e ( )
. :
s e t c o o k i e ( " s t a t e " , "", t i m e ( ) + 3 600) ; # :
1
s e t c o o k i e ( " N a m e " , $Name, t i m e ( ) + ( 3 * 8 6 4 0 0 ) )
3
S m k t i m e ( ) .
, . .
: , , , <,
. - ,
, . npi-
cookie
m k t i m e ( ) .
s e t c o o k i e ( " s t a t e " , "", m k t i m e ( 3 , 0 , 0 , 4 , 1 , 2 0 0 3 ) ) ;
# c o o k i e 1 2003 0 3 : 0 0
s e t c o o k i e ( " s t a t e " , "", m k t i m e ( 1 3 , 0 , 0 , , , ) ) ;
1 3 : 0 0
cookie
. :
setcookie("") ;
setcookie("", " " ) ;
s e t c o o k i e () . i
- Web-. cookie
- ,
. . , ",
".
HTML-
. , HTML- S u b m i t .
, UP.L-
194
IV. -
<f orm>.
:
<form action="processform.php" method="POST">
<input type="submit" value="">
</form>
(). ( . 10).
.
, Web-, ,
(hidden fields). ,
.
.
n e x t p a g e . php:
<?php
$acct = "admin";
echo "<form a c t i o n = ' n e x t p a g e . p h p ' method='POST'>
<input t y p e = ' h i d d e n ' name='acct' v a l u e = ' $ a c c t ' >
<input t y p e = ' s u b m i t ' value=' '>
</form>\n";
?>
Ha Web- ,
.
n e x t p a g e . php,
$_POST [' a c c t ' ] .
Web-. , ,
.
, , .
(session) ,
Web-. Web-
,
. 4.0,
, .
.
( ) Web-.
.
1. (session number).
,
(, 523afal5f4a8e05e95241481c0cbc71e).
.
$PHPSESSID.
2. ,
. . ,
11. Web-
195
, s e s s i o n . s a v e _ p a t h
php. i n i . .
3. .
cookie,
.
t r a n s - s i d p h p . i n i . (
, "
cookie".)
4. .
$_SESSION.
4.1.2 t r a n s - s i d
, - - e n a b l e - t r a n s - s i d
, s e s s i o n _ s t a r t ().
, . ,
. .
!
cookie, s e s s i o n _ s t a r t () .
, - Web-. i ", ".
s e s s i o n _ s t a r t : ()
. php. i n i , : s e s s i o n . a u t o _ s t a r t 1.
, Web-.
s e s s i o n _ s t a r t () .
, Web-
. .
. : s e s s i o n _ d e s t r o y ().
, .
.
, - .
unset($1,
$2,
...);
Web-, $_SESSION :
$_SESSION['_'] = " ";
$_SESSION.
196
IV. -
u n s e t ( ) :
unset($_SESSION['_']);
,
. 11.1 ,
10.2 .
<?php
/ * :
sessionTestl.php
* :
*
.
*/
session_start();
$_SESSION['session_var'] = "";
?>
<html>
<headxtitle>TecTOBaH 1 ceaHca</titlex/head>
<body>
<> .
<form action="sessionTest2.php" method="POST">
<input type="text" name="form_var" value="">
<input type="submit" value=" ">
</form>
</body>
</html>
s e s s i o n _ s t a r t ()
s e s s i o n _ _ v a r .
,
s e s s i o n T e s t 2 . p h p .
<?php
/ * :
sessionTest2.php
* :
.
*/
session_start();
?>
<html>
<headxtitle>TecTOBaH 2 ceaHca</titlex/head>
<body>
<?php
$session_var = $_SESSI0N['session_var'];
$form_var = $_POST['form_var'];
echo "session_var = $session_var<br>\n";
echo "form_var = $form_var<br>\n";
?>
</body>
</html>
,
( s e s s i o n T e s t l . php).
11. Web-
197
s e s s i o n T e s t l .php
, :
session_var =
form_var =
, , s e s s i o n _ v a r ( )
form_var ( ), $_SESS:ON
$_POST .
cookie
cookie.
,
cookie. ,
.
S $PHPSESSID .
S cookie $PHPSESSID
.
cookie, ; -.
S SID, "" PHPSESSID=-.
S
t r a n s - s i d p h p . i n i .
,
, .
t r a n s - s i d .
s e s s i o n . u s e _ t r a n s _ s i d = php. i n i .
0, t r a n s - s i d , 1 .
Web-.
t r a n s - s i d , .
S .
,
cookie, .. t r a n s - s i d
, .
S . URL- ,
, .
.
trans-sid
t r a n s - s i d cookie, URL
. ,
header () GET URL-.
,
POST, .
$PHPSESSID.
198
IV. -
URL-,
Web-. URL ,
. ,
< href="newpage.php">
.
< href="HTTP://www.janetscompany.com/newpage.php">
.
trans - s i d
t r a n s - s i d 0
cookie,
. .
, SID,
.
"-=", URL :
< href="nextpage.php?<?php echo SID?>" > </>;
SID
. echo SID
:
PHPSESSID=f8544042bf883ca93b5e2c5dc6794755
, URL :
nextpage.php?PHPSESSID=f8544042bf883ca93b5e2c5dc6794755
( )
.
:
POST. ,
. , :
<?php
$PHPSESSID = s e s s i o n _ i d ( ) ;
echo "<form a c t i o n = ' n e x t p a g e . p h p ' method='POST'>
<input t y p e = ' h i d d e n ' name='PHPSESSID'
value='$PHPSESSID'>
cinput t y p e = ' s u b m i t ' value=' '>
</form>";
?>
.
1. $PHPSESSID ,
s e s s i o n _ i d ( ) .
2. $PHPSESSID
.
, $PHPSESSID
n e x t p a g e . php.
11. Web-
199
Web-yaa
.
. >
. ,
, .
.
1. .
2. .
3.
.
4. , Web-.
5. .
:
<?php
session_start()
if (@$_SESSION['login'] != "go")
{
header("Location: loginPage.php");
exit();
}
?>
l o g i n ( ) . ,
, , . .
3azfttf3tca
,
Web-. , Web- ,
.
Web- HTML, :
<form enctype="multipart/form-data"
action="processfile.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<input type="file" name="user_file">
200
IV. -
S e n c t y p e <form>.
m u l t i p a r t / form-data.
S ,
MAX_FT.LE_SI.ZE ( ). ,
MAX_FILE_SIZE.
MAX_FILE_SIZE php. i n i
.
upload_max_f i l e s i z e . MAX_FILE_SIZE
u p l o a d _ m a x _ f i l e s i z e .
, u p l o a d _ m a x _ f i l e s i z e
php. i n i . 2 .
post_max_size.
, POST.
post_max_size 8 , .
/ f i l e , .
MAX_FILE_SIZE
. .
.
,
. phpinf () ,
. upload_tmp_dir
php. i n i . p h p . i n i , ,
.
,
. $_FILES,
.
.
$_FILES['-']['name']
$_FILES['-']['type']
$_FILES['-']['tmp_name']
$_FILES['-'] [ ' s i z e ' ]
, , :
<input t y p e = " f i l e " name="user_file">
t e s t . t x t
:
$_FILES[user_file][name] = test.txt
$_FILES[user_file][type] = text/plain
$FILES[user_file][tmp_name] = D:\WINNT\php92C.tmp
$_FILES[user_file][size] = 435
11. Web-
201
_FILES name ; t y p e ;
tmp_name ; s i z e . ,
name , tmp_name .
, tmp_name
, s i z e 0.
Windc ws
(Windows Win98/XP Winnt Win2000) /tmp Unix/Linux.
, p h p . i n i .
;upload_tmp_dir =
. :
upload_tmp_dir = d : \ t e m p f i l e s
tempf i l e s .
, .
]
move_uploaded_f i l e () :
move_uploaded_file(/__,
/__);
tmp_name $_FILES
. , : \ d a t a \ n e w _ f i l e . t;:t,
move_uploaded_f i l e () :
move_uploaded_file($_FILES['user_file'] t'tmp_name'],':\data\new_file.txt');
, , (
: \ d a t a \ ) , , move_upload_f i l e ()
.
.
.
.
.
11.3. .
. ,
.
.11.1. '
11.3.
POST
<?php
/* : uploadFile.php
* :
HTTP
*
POST.
*/
202
IV. -
if(!isset($_POST['Upload']))
#5
{
include("form_upload.inc");
} # endif
#9
else
{
#11
if($_FILES['pix']['tmp_name'] == "none")
{
echo "<> .
. 500K.<br>",
include("form_upload.inc");
exit();
}
if(!ereg("image", $_FILES['pix']['type']))
#16
{
echo "<> .
.</><>";
include("form_upload.inc");
exit();
}
else
#23
{
$destination = 'c:\data'. "\\".$_FILES['pix']['name'];
$temp_file = $_FILES['pix']['tmp_name'];
move_uploaded_file($temp_file, $destination);
echo "<>< :</>
{$_FILES['pix']['name']}
({$_FILES['pix']['size']})</p>";
}
}
?>
11.3 .
/ 5 i f ,
. ,
, 11.4.
S 9. e l s e .
S 11 i f
. ,
.
S 16 .
,
.
S 23. e l s e (.. )
.
11.4 ,
.
11. Web-
203
11.4. ,
<!-- : form_upload.inc
:
-->
<html>
<headxtitle>3arpy3Ka aa</title></head>
<body>
<1><> ,
,
,
.</li>
<>
-;/li>
</ol>
<div align="center"><hr>
<form enctype="multipart/form-data"
action="uploadFile.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<input type="file" name="pix" size="60">
<pxinput type="submit" name= "Upload"
value=" ">
</form>
</bodyx/html>
'
- [] Q
) jj? * g >
-.'
&
http:caliost/test/uptoedFle.php
1, , , ,
.
2. , .
1 ...
*|
. 111.
204
IV.
, HTML-.
. 11.1.
.
JavaScrifit
?/&
Web- ,
JavaScript. , Web-
, ..
. ,
. ,
, .
Web-
, JavaScript.
JavaScript,
. ,
JavaScript, ,
.
JavaScript .
, JavaScript .
( JavaScript JavaScript
"" , "".)
JavaScript
JavaScript, HTML,
. , HTML.
, JavaScript HTML- Web-,
:
<script language="JavaScript">
JavaScript
</script>
JavaScript , HTML:
echo. :
<?php
, :
: 03/24/2003 12:01:47
JavaScript, HTML,
echo.
.
11. Web-
205
JavaScript
JavaScript , HTML. , $ s t r i n g
:
<?php
$ s t r i n g = " : " ;
echo " < s c r i p t l a n g u a g e = \ " J a v a S c r i p t s " >
< ! -document.write('$string'
+ document.lastModified + '<br>')
/ / -->
</script>";
?>
, JavaScript , >
. :
<?php
$ s t r i n g = " : " ;
echo " < s c r i p t l a n g u a g e = \ " J a v a S c r i p t \ " >
<!
v a r message = \ " $ s t r i n g \ " ;
document.write(message
+ document.lastModified + '<br>')
/ / >
</script>";
?>
JavaScript , ""
JavaScript . JavaScript
. UEL, cookie .
206
IV. -
12
* ...
>
>
>
>
>
.
(session).
, . 11,
cookie.
cookie.
.
, .
.
.
, a t Linux/Unix.
, Notepad vi.
. ""
. ,
"" , 20 .
,
, MySQL Oracle.
, , ,
. .
. ,
SQL,
.
, .
.
I
S .
. -
. ,
.
S .
,
.
.
S .
, .
, , ,
( )
. .
,
. , i pe , .
.
S .
, .
,
.
S .
,
. !
.
S . ]
(, ) ,
.
, .
. ,
.
5 SQLite,
. SQLite
, >[
SQL.
. SQLite
,
.
/&
, . ,
.
.
1. .
2. .
3. .
.
208
IV. -
.
$fh = f o p e n ( " _ " ,
"");
$ f h (file handle),
.
.
,
, .
. 12.1.
12.1.
+
w
w+
. ,
. ,
_ ( f i l e n a m e . t x t ) ,
( : / d a t a / f i l e n a m e . t x t ) U R L ( h t t p : / / y o u r s i t e . c o m / f i l e n a m e . t x t ) .
f i l e l . t x t
f o p e n () :
$fh = f o p e n ( " f i l e l . t x t " , " r " ) ;
f i l e l . t x t .
, . ,
(
, . 4):
W a r n i n g : f o p e n ( f i l e l . t x t ) : f a i l e d t o open s t r e a m : No s u c h f i l e o r
d i r e c t o r y i n d : \ t e s t 2 . p h p on l i n e 15
(: f o p e n ( f i l e l . t x t ) : :
d : \ t e s t 2 . p h p 15)
,
. , ,
.
$fh = f o p e n ( " f i l e l . t x t " , " r " ) o r d i e ( " H e " ) ;
8, d i e ()
.
12.
209
f open () :
$fh = f o p e n ( " : / t e s t d i r / f i l e l . t x t " , "w") ;
, .
, . ( ,
.)
:
if(is_dir(":/tester") )
{
"w");
,
.
Web-
, Web-, :
$fh = f o p e n ( " h t t p : / / j a n e t . v a l a d e . c o m / i n d e x . h t m l " , " " ) ;
URL- .
:
fclose($fh);
$fh, ) .
, /
f w r i t e () :
fwrite($fh,
);
$fh,
, , .
. :
$today = date("Y-m-d");
$fh = f o p e n ( " f i l e 2 . t x t " , " a " ) ;
fwrite($fh, $ t o d a y ) ;
fclose($fh);
f i l e 2 . t x t . . , >
. .
. ,
, , , . ,
f w r i t e () , . TJK,
:
2 003-04-222003-04-22
210
IV. -
.
f w r i t e () :
fwrite($fh, $today"\n");
\ f i l e 2 . t x t :
2003-04-22
2003-04-22
, .
,
.
f g e t s () :
$line = fgets($fh);
$fh , . f g e t s O
, .
$ l i n e .
. f eof ( ) .
:
while(Ifeof($fh))
{
$line = fgets($fh);
echo "$line";
}
f eof () TRUE
$fh. w h i l e
.
,
, :
2003-04-22
2003-04-22
'
, f g e t s ()
. , :
while(ifeof($fh))
{
$line = rtrim(fgets($fh));
echo "$line";
}
r t r i m ( ) .
:
2003-04-222003-04-22
.
f g e t s () :
$line = fgets($fh, ) ;
12.
211
- 1 ,
. :
while{Ifeof($fh))
{
$char4 = fgets($fh, 5 ) ;
echo "$char4\n";
}
,
. :
2003
-0422
2003
-0422
,
.
. 1
:
$fh = f o p e n C f i l e 2 . t x t " , " " ) ;
while(Ifeof($fh))
{
$content[] = fgets($fh);
}
fclose($fh);
$content, ,
, .
f i l e ( ) . IT :
$content = f i l e C f i l e 2 . t x t " ) ;
, $ c o n t e n t .
, f i l e ()
.
. ,
f i l e () f g e t s ,
, .
f i l e ()
(. 8):
$content = f i l e ( " f i l e 2 . t x t " , 1 ) ;
1 , f i l e 2 . t x t
, .
. ,
, re.
$content = file_get_contents("file2.txt", 1 ) ;
212
IV. PHP-
f i l e _ g e t _ c o n t e n t s () f i l e (),
, , .
$ c o n t e n t :
echo $ c o n t e n t ;
:
2003-04-22
2003-04-22
, $ c o n t e n t ,
, .
.!
f i l e _ g e t _ c o n t e n t s ( ) PHP 4.3.O.
.
,
.
. ,
.
, ..
.
. ,
. , 20
, 20 ..
.
f w r i t e (), .
CSV (comma-separated values , ),
- , (comma-delimited file),
. CSV
, ( ).
(, Microsoft
Excel). CSV
, MySQL Microsoft Access. CSV
.
CSV- : ,
, , .
, CSV:
, . 1234, , OR, 99999
, . 5678, , ME, 11111
, . 1234, , , 88888
Excel ,
. -. Outlook Express
.
CSV.
$address[] = " , . 1234, , OR, 99999";
$ a d d r e s s [ ] = " , . 5678, , ME, 11111";
$address[] = " , . 1234, , , 88888";
$fh = f o p e n ( " a d d r e s s b o o k . t x t " , " a " ) ;
12.
213
for
($i=0;$i<3;$i++)
fwrite($fh,$address[$i].
"\n");
fclose($fh);
CSV- f i l e f g e t s ( ) ,
, " ". "
f g e t c s v ( ) .
,
. :
$address = fgetcsv($fh, 1000);
$ f h
1000 . f g e t c s v () :
$ a d d r e s s [ 0 ] =
$ a d d r e s s [ l ] = . 1234
$ a d d r e s s [ 2 ] =
$ a d d r e s s [ 3 ] = OR
$ a d d r e s s [ 4 ] = 99999
CSV . , , ,
-. :
, . , . 1234, , OR, 99999
(): . , ..
. , ( \ t ) . (
.) TSV (tab-separated
values , ).
g e t c s v () :
$ a d d r e s s = f g e t c s v ( $ f h , 1000, " \ t " ) ;
, .. , .
12.1 , CSV TSV.
12.1. , CSV TSV-
<?php
/ * :
* :
Convert
CSV-
TSV-. CSV-
*/
$myfile = " t e s t i n g " ;
function convert($filename)
.CSV.
#7
#8
if(@$fh_in
fopen("{$filename}.csv"
"r'D
#10
a");
#12
#13
214
#15
#16
IV. -
#27
return FALSE;
}
echo " !\n";
return TRUE;
}
convert($myfile);
#32
#34
?>
12.1 .
.
S 7 .
S 8 c o n v e r t () $f ilename.
S 10. . csv.
, if.
e l s e 27.
S 12.
. t s v . , , ..
, .
S 13. w h i l e ,
.
S 15. $ l i n e .
.
S 16. ,
- . , (\).
,
.
S 20. ,
TSV .
S 21. .
. implode ()
$ l i n e ,
- (\t).
S 27. e l s e ,
. ,
c o n v e r t () FALSE.
S 32. , TRUE.
S 34. c o n v e r t (),
$myf i l e .
12.
215
Padotna
,
,
, .
, .
(database) ,
, .
, , ,
. , Amazon
, .
,
.
() (DBMS Database Management System).
(relational),
.
. .
S
S
S
^
S
*
S
IBMDB2
Informix
Ingres
Microsoft SQL Server (MS SQL)
mSQL
MySQL
Oracle
PostgreSQL
Sybase
IV. -
S . .
, . ,
MySQL, mSQL PostgreSQL
, , .
, Sybase, MS SQL Server Oracle,
,
.
S .
. , mSQL
,
. , Oracle
, , ,
. , ,
,
. ,
.
S .
(, ), . ,
mSQL MySQL ,
Oracle
.
S . ,
.
S . -
.
,
. -
.
/ .
.
.
.
,
-.
, . ,
, .
, : .
, ,
. ,
.
.
, , ,
. Catalog (),
12.
217
()
D e s c r i p t i o n ()
S i z e ()
Color ()
P r i c e ()
, C a t a l o g
.
, ,
.
.
.
, . ,
Web- ,
.
,
.
:
.
.
[.
.
, MySQL 4.0
mysgl_connect () mysql_query (),
MySQL 4.1 m y s g l i _ c o n n e c t () mysqli_cruery ().
Sybase s y b a s e _ c o n n e c t () sybase_guery ().
ODBC,
. Web-
.
,
( ).
Unix/Linux/Mac
. . , mSQL
./configure --with-msql=/usr/msgl
218
IV. -
. 12.2 ,
. ,
, DIR . :
./configure --with-msql
12.2.
D I R
IBM DB2
/home/db2instl/sqllib
MySQL 4.0
with-ibm-db2=D/fl
with_informix=D/fl
with-ingres=D/R
with-msql=D/R
with-mysql=D/fl
MySQL 4.1
wi th-mysql i =?
.
D I R
m y s q l _ c o n f i g ,
MySQL 4.1
Oracle 7
with-oci8
O R A C L E _ H O M E
Oracle
with-oracle=D/fl
PostgreSQL
with-pgsql=D/ft
/usr/local/pgsql
with-sybase=D/fl
/home/Sybase
with- Sybase- t=DIR /home/sybase
Informix
Ingres II
mSQL
/II/ingres
/usr/local/Hughes
/usr/local/mysql
O R A C L E _ H O M E
Sybase
Sybase-CT
.
phpinf (), .
Windows
Windows
.
1. (Dynamic Link
Library DLL) .
2. .
, ,
phpinf () ,
.
(ill-
dll- zip-,
Web- .
. , -
12.
219
PHP, e x t (, c : \ p h p \ e x t ) .
.
dll- , : \ p h p . ,
, PostgreSQL Windows 2000,
: \ p h p \ e x t \ p h p _ p g s q l . d l l . (
c d .)
,
dll- .
, .
p h p . i n i . :
;extension=php_pgsql.dll
;extension=php_msql.dll
,
. , .
, , , .
. :
extension=php_pgsql.dll
PostgreSQL.
, Web-.
p h p . i n i ,
, :
Unknown(): U n a b l e t o l o a d dynamic l i b r a r y ' p h p _ p g s q l . d l l ' .
The s p e c i f i e d module c o u l d n o t b e f o u n d .
(Unknown () : He ' p h p _ p g s q l . d l l .
. )
( dll-
p h p . i n i ) , , :
The dynamic l i n k l i b r a r y m s q l . d l l c o u l d n o t b e found i n t h e s p e c i f i e d p a t i
( m s q l . d l l ^)
MS SQL.
MS SQL Server Client Tools. - MS SQL.
MySQL. , <|
p h p _ m y s q l . d l l MySQL 4.0 p h p _ m y s q l i . d l l
MySQL 4.1 .
SQL (Structured
Query Language ). SQL,
(query), , ;
220
IV. -
. , SQL-
, , ..
SQL,
. , mSQL
SQL. Oracle Sybase SQL,
.
SQL .
, -
. , mySQL, 2- , "",
MySQL.
SQL SQL "", 5- ,
"".
SQL-,
.
SELECT * FROM
, _.
* - (wild card),
. , C a t a l o g
(. " ").
Product .
Product
SELECT * FROM Product
, SQL-:
INSERT INTO _ (_1, _2,
...)
VALUES {!,
2,
...)
_ ,
. ,
:
INSERT INTO Product (Type, D e s c r i p t i o n , Size, Color, Price)
VALUES ("", "100% ", "L", "", 20)
, , .
, ,
. .
, .
.
1.
2.
3.
4.
.
SQL- .
.
.
12.
221
. :
,
.
/ .
, .
, .
(,
mycompany.com), IP- (172.17.204.2).
, ,
l o c a l h o s t .
S . ,
,
.
S . ,
.
S .
,
, .
,
i n c l u d e ().
(. 8),
. , i n f o . i n c
:
$host - "localhost";
$account = "admin";
$password = "secret";
$dbname = "Catalog";
, ,
:
include("info.inc");
. .
, . , Web
MySQL. MySQL 4.0
$connect = mysql_connect($host, $account, $password);
$db = m y s q l _ s e l e c t _ d b ( " C a t a l o g " , $connect);
,
. MySQL 4.1
:
$connect = mysqli_connect($host, $account, $password);
$db = mysqli_select_db($connect, " C a t a l o g " ) ;
( MySQL). ,
mSQL Sybase :
222
IV. -
Oracle ,
ORACLE_SID.
, ,
. Web-
www.php.net.
,
, , , .
SQL,
. ,
, . ,
SQL- MySQL :
$sql = "SELECT * FROM Product";
$ r e s u l t = mysql_query($sql, $connect);
SQL- $sql.
Product. mysql_query () SQL-
$sql , $connect.
1, $ r e s u l t .
PostgreSQL SQL :
$sql = "SELECT * FROM Product";
$ r e s u l t = pg_query($connect, $ s q l ) ;
SQL- $sql,
. , Oracle
:
$sql = "SELECT * FROM Product";
$query = OCIParse($connect, $sql);
$result OCIExecute($query);
SQL-. ( ,
.) ,
.
SQL- .
.
, .
$first_name = "";
$last_name = "";
12.
223
, , - . , ;
Web- ,
..
, SQL-.
.
.
.
. MySQL
:
$row = m y s q l _ f e t c h _ a r r a y ( $ r e s u l t ) ;
SQL-
$ r e s u l t . m y s q l _ f e t c h _ a r r a y ()
( $ r e s u l t ) .
m y s q l _ f e t c h _ a r r a y () $row
:
$ r o w [ ' f i r s t N a m e ' ] =
$ r o w [ ' l a s t N a m e ' ] =
, , :,
. ,
PostgreSQL
while($row=pg_fetch_asoc($result))
{
foreach($row as $value)
{
echo "$value<br>";
}
}
w h i l e .
$row. ,
$row f o r e a c h .
PostgreS QL
f o r . :
$Nrows = p g _ n u m _ r o w s ( $ r e s u l t ) ;
f o r ( $ i = 0 ; $i<$Nrows; $i++)
{
$row = p g _ f e t c h _ r o w ( $ r e s u l t , $ i ) ;
foreach($row as $value)
{
echo "$value<br>";
}
}
224
IV. PHP-
pg_num_rows ()
. ( MySQL
mysql_num_rows ( $ r e s u l t ) . ) for ,
. (.. $row)
foreach. , pg_fetch_row()
$i, , .
Oracle :
$Nfields = OCINumCols($result);
while (OCIFetch($result))
{
f o r ( $ i = l ; $i<=$Nfields; $i++)
{
$value = O C I R e s u l t ( $ r e s u l t ,
echo "$value<br>";
$i);
}
}
$ N f i e l d s ,
OCIFetch () . w h i l e
, .
OCIResult () ,
OCIFetch ( ) . f o r
.
,
. ,
. , mysql_af f e c t _ r o w s ()
, ,
pg_f i e l d _ n a m e () .
,
, ,
Web- www.php.net. .
MySQL mySQL, 2- ,
"".
.
( ).
. , MySQL
:
mysql_close($connect);
.
ocilogoff($connect);
# Oracle
pg_close($connect);
# PostgreSQL
mssql_close($connect); # MS SQL
_connect ()
. , ,
. ,
MySQL :
12.
225
226
IV. -
:
: Table 'Catalog.productt' doesn't exist
( : 'Catalog.productt' )
,
d i e () SQL (
m y s q l _ e r r o r ()) .
. , ,
. ( . 4.)
...
,
- .
.
PostgreSQL S a l e s (),
Customer (). ,
. 12.2 ,
Customer Web-.
12.2.
<?php
/* : DisplayCustomers
* :
*
PostgreSQL
*
Web-.
*/
include (" info, inc") ,- #
$connect = pg_connect("host=$host user=$user
password=$password dbname=Sales")
or die("He ");
$sql = "SELECT * from Customer";
$result = pg_query($sql)
or die (" :" .mysql_error ()) ,$Nrows = pg_num_rows($result);
echo "<html>
<headxtitle>CnncoK oyaee</title></head>
<body>
<table width=\"100%\" border=\"0\">\n";
for($i=0;$i<$Nrows;$i++)
{
echo "<tr>";
$row = pg_fetch_row($result,$i);
echo "<td>{$row[l]}, {$row[0]}</td>
<td>{$row[2]}</td>";
echo "</tr>\n";
}
echo "</tablex/body></html>";
..
?>
12.
227
C u s t o m e r ,
f o r Web- HTML.
( 12.3) ,
, . MySQL. ,
P r o d u c t T y p e ( ) D e s c r i p t i o n ().
12.3.
<html>
<head><title>TecTHpoBaHMe <J>aiiOB</title></head>
<body>
<?php
/* : DisplayCheckboxes
* :
MySQL
*
Web-.
*/
include("info.inc"); #
$connection = mysql_connect($host,$user,$password)
or die ("He ");
$db = mysql_select_db("Catalog",$connection)
or die ("He ");
$query = "SELECT * FROM ProductType";
$result = mysql_query($query)
or die("3anpoc : " .mysql_error () ) ,echo "<htmlxhead><title>ToBapbi</title></head>
<bodyxdiv style='margin-left: .2in'>
<> ?</>\";
## ##
echo "<form action='processform.php' method='post'>\n";
echo "<hrxtable width='100%'>" ;
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td width='20%'><b><input type='checkbox'
name=\"interest['ProductType']\ "
value=\"{$row['ProductType']}\">{$row['ProductType']}
</bx/td>\n" ;
echo " < t d > { $ r o w [ ' D e s c r i p t i o n ' ] } < / t d > " ;
echo " < / t r > \ n " ;
}
value='
'>
?>
</divx/bodyx/html>
HTML-. w h i l e
$ r e s u l t ,
HTML-.
, SQL-.
. ;
.
228
IV. -
12.3 ,
. 12.1. ,
.
- Microsoft Internet txplorer
"
'
\\
[flf|
...
^ ' ?
^2)
.**: { http://localhost/test/DiaplayCheckboxes.php
?
"
.
, , .
CD-
* *
. 12.1. Web- ,
12.3
ftactuufienusi SQClte
SQLite ,
, .
,
SQL. SQLite ,
. ,
SQLite SQL,
, .
SQLite
. SQLite .
. , , SQLite
, ,
,
, .
SQLite
, .
12.
229
SQL, SQL-
. .
1. .
,
. :
$db = sqlite_open("testdb");
s q l i t e _ o p e n () t e s t d b .
, .
2. SQL-.
SQL- s q l i t e _ q u e r y ( ) .
$sql = "SELECT * FROM Product";
$result = sqlite_query($db, $sql);
3. .
, SOL .
, . .
$row = s q l i t e _ f e t c h _ a r r a y ( $ r e s u l t ) ;
$row :
$row['firstName'] =
$row['lastName'] =
w h i l e .
while($row=sqlite_fetch_array($result))
{
foreach($row as $value)
echo "$value<br>";
}
4. .
sqlite_close($db);
SQLite
, " ". ,
d i e ( ) . SQLite
s q l i t e _ e r r o r (), SQLite
SQL-. :
$sql = "SELECT * FROM Product";
$result = sqlite_query($sql)
or die(" :".sqlite_error());
$row = sqlite_fetch_array($result);
, , SQLite. ,
SQLite , 6aiax
, .
230
IV. -
13
PHP
3 aificu ...
>
>
>
>
^ , \*
. ,
, . , ,
, .
,
. ,
.
, , (file).
, (, )
(directory) (folder).
(file system).
(root) , : \ Windows / Linux.
,
, .. .
,
. ,
. ,
, .
,
(. 12). , ,
, .
. , ,
.
.
- ,
,
. ,
,
. ,
" ".
- .
, .
, , f i l e _ e x i s t s ( ) .
$result = file_exists("stuff.txt");
$ r e s u l t TRUE,
FALSE. f i l e _ e x i s t s () . :
if(!file_exists("stuff.txt") )
{
echo " !\";
}
,
.
. 13.1 ,
13.1. ,
is_file("stuff.txt")
,
, ,
TRUE FALSE
is_dir("stuff.txt")
TRUE FALSE
is_executable("do.txt")
TRUE FALSE
is_writable("stuff.txt")
TRUE FALSE
is_readable("stuff.txt")
TRUE FALSE
fileatime("stuff.txt")
Unix
(, 1 0 5 7 1 9 6 1 2 2 1
filectime("stuff.txt")
Unix
FALSE
filemtime("stuff.txt")
Unix
FALSE
filegroup("stuff.txt")
()
FALSE
) FALSE
()
) F A L S E
filesize("stuff.txt")
F A L S E
filetype("stuff.txt")
(, f i l e ,
d i r , l i n k , c h a r )
F A L S E ooe^
basename (" / 1 1 / d o . t x t " )
d i r n a m e (" / t i / d o . t x t " )
232
do.txt
/ti
IV. -
Linux/Unix/Mac,
Windows.
p a t h i n f ( ) ,
. :
$ p i n f o = p a t h i n f (" / t o p d i r / n e x t d i r / s t u f f . t x t " ) , $ p i n f :
$pinf[dirname] = /topdir/nextdir
$pinfo[basename] = stuff.txt
$pinf[extension] = txt
1_()
, ,
FALSE. , i s _ d i r ( " t y m e " )
FALSE, t y m e , .
, t y m e .
, ,
Unix.
d a t e () (. 5).
,
12 .
, .
.
. ( ) .
("f i l e o l d . t x t " , " f i l e n e w . t x t " ) , f i l e o l d . t x t f i l e n e w . t x t .
f i l e n e w . t x t , .
, :
if(!file_exists("filenew.txt"))
{
copy("fileold.txt",
"filenew.txt");
}
else
{
e c h o " ! \ n " ;
}
r e n a m e ( ) :
rename("oldname.txt", "newname.txt");
,
:
Warning: r e n a m e ( f i l e o l d . t x t , f i l e n e w . t x t ) : F i l e e x i s t s i n c : \ t e s t . p h p
on l i n e 17
u n l i n k ( ) :
unlink("badfile.txt");
13. PHP
233
b a d f i l e . t x t . ,
, , .
.
, (directory),
(folder). ,
, .
mkdi ( ) :
mkdir("testdir");
t e s t d i r
, . ,
/ t e s t / t e s t . p h p , / t e s t / t e s t d i r .
,
:
Warning: m k d i r ( ) : F i l e e x i s t s i n d : / t e s t / t e s t . p h p on l i n e 5
i s _ d i r ( ) . :
if(!is_dir("mynewdir"))
{
mkdir("mynewdir");
}
else
{
e c h o " !
";
.
, (. ",
").
. :
mkdir("/topdir/nextdir/mynewdir");
m k d i r () ,
.
mkdir("../mynewdir");
/ t o p d i r / t e s t / m a k e d i r . p h p ,
/ t o p d i r / m y n e w d i r .
:
c h d i r (" . . / a n o t h e r d i r " ) ,-
. ,
,
.
.
:
$dh = o p e n d i r ( " / t o p d i r / t e s t d i r " ) ;
234
IV. PHP-
o p e n d i r () , ,
. ,
:
Warning: opendir(testdir): failed to open dir: Invalid argument in
testl3.php on line 5
, o p e n d i r ( ) , $dh
(directory handle). ,
.
r e a d d i r ():
$filename = r e a d d i r ( $ d h ) ;
$f ilename ,
. , while. :
while($filename = r e a d d i r ( $ d h ) )
{
echo $filename.
"\n";
, r e a d d i r ()
.
, Web- " ",
.
o p e n d i r () r e a d d i r ( ) . 13.1 ,
.
13.1. , " "
<?php
/* : displayGallery
:
,
*
.
*/
echo "<html><head><title>aepe M3o6pa;KeHttH</title></head>
<body>";
$dir = "../testl/testdir/";
#8
$dh = opendir($dir);
#9
while($filename = readdir($dh))
#10
{
$filepath = $dir.$filename;
#12
if(is_file($filepath)and ereg("\.jpg$",$filename))
#13
{
$gallery[] == $filepath;
}
}
sort($gallery);
#16
foreach($gallery as $image)
#17
{
echo "<hr>";
echo "<img src='$image'><br>";
}
?>
</bodyx/html>'
13. PHP
235
.
.
S 8. $ d i r ,
. (/) ,
(\) ( Windows).
S 9. .
S 10. w h i l e , .
S 12. $f i l e p a t h , : .
8 /, $f i l e p a t h
.
S 13. , , -.
. jpg. ,
$ g a l l e r y .
S 16.
$ g a l l e r y .
S 17. f o r e a c h Wsb.
CUCtfieAtbl
,
. , i LTH
, Windows d i r , Unix/Linux I s
. ( ,
Windows 2000, : Start^Programo^
Accessories^Command Prompt (^1* .)
,
.
. , .
, .
, opendir () r e a d d i i ()
(. ), ()
,
. ,
, ,
.. , < , I s d i r ,
o p e n d i r r e a d d i r . , , Perl. ! .
.
236
IV. -
j
| . , ,
| . .
!
|
!
|
. 2 > & 1 .
:
$result = system)"di c:\php");
I- s y s t e m { ) c : \ p h p ,
| d i r . , d i ,
I . :
I $result = system("di c:\php 2>&1");
! . Windows 2000
| :
::::
~~
.
S (" ").
,
.
/ system ( ) . ,
.
S exec (). ,
.
S p a s s t h r u ().
.
.
,
. , I s d i r , rename
mv, rm d e l , ,
.., .. ,
, .
, .
dir
rm badfile.txt
dir | sort
cd c:\php ; dir ( Windows)
"cd c:\php && dir" ( Windows 2000)
dir > dirfile
sort < unsortedfile.txt
13. PHP
237
<*oS&
. (, ,
),
.
,
.
fio .
. :
$result.= "dir c:\php4;
$ r e s u l t d i r , ..
: \php:
Volume in drive C has no label.
Volume Serial Number is 394E-15E5
Directory of c:\php
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
02/25/2004
238
10: 48a
10: 48a
04: 30p
04: 30p
04::3 0p
04::3 0p
04::3 0p
04::3 0p
04::30p
04::3 0p
04::3 0p
04::3 0p
04 :3 0p
04 :30p
04;:30p
04 :30p
04;:3 0p
04 :30p
04 :30p
04 :30p
04 :30p
04 :30p
04 :30p
04 :30p
04 :3 0p
04 :3 0p
04 :30p
04 :30p
04 :30p
04 :30p
04 :30p
04 :3 0p
04 :3 0p
<DIR>
<DIR>
<DIR>
<DIR>
<DIR>
417,792
90,112
346,624
70
32,081
876,544
47,027
165,643
233,472
3,208
57,344
18,151
278,800
<DIR>
dev
ext
extras
fdftk.dll
fribidi.dll
gds32.dll
go-pear.bat
install.txt
libeay32.dll
libintl-l.dll
libmhash.dll
libmysql.dll
license.txt
msql.dll
news.txt
ntwdblib.dll
PEAR
53,248
php-cgi.exe
28,672
php-win.exe
28,672
php.exe
3,872
php.gi f
39,284
php.ini-dist
40,899
php.ini-recommended
40,960
php5activescript.dll
36,864
php5apache.dll
36,864
php5apache2.dll
53,248
php5apache_hooks.dll
503,320
php5embed.lib
28,672
php5isapi.dll
28,672
php5nsapi.dll
3,452,92 8 php5 ts.dll
IV. PHP-
02/25/2004 04:30
02/25/2004 04:30
02/25/2004 04:30
30 F i l e ( s )
6 Dir(s)
1,224
snapshot.txt
159,744
ssleay32.dll
49,152
php_mysql.dll
7,153,163 b y t e s
251,727,872 b y t e s free
,
safe_mode , .. Off
( ).
system()
system () , ,
. :
$result = system("dir c:\php");
system() c : \ p h p ,
$ r e s u l t :
11 D i r ( s )
566,263,808 b y t e s free
exec ( )
exec () ,
. ,
, .
system (), exec () .
, , ,
. exec () :
$result = exec("dir c:\php");
,
$ r e s u l t d i r :
11 D i r ( s )
566,263,808 b y t e s free
d i r ,
exec ():
$result = exec("dir c:\php", $dirout);
$ d i r o u t
: \php.
:
f o r e a c h ( $ d i r o u t as $ l i n e )
{
echo "$line\n";
}
:
Volume in drive D has no label.
Volume Serial Number is 3 94E-15E5
Directory of d:\php
02/25/2004
02/25/2004
10:48a
10:48a
<DIR>
<DIR>
13. PHP
239
02/25/2004
02/25/2004
02/25/2004
02/25/2004
04:30p
04:30p
04:30p
04:30p
<DIR>
<DIR>
<DIR>
417,792
dev
ext
extras
fdftk.dll
$ d i r o u t
:
e c h o $ d i r o u t ' [ 3 ] ,echo $ d i r o u t [ 7 ] ;
:
Directory of C:\PHP
02/25/2004 04:30
<DIR>
dev
p a s s t h r u ( )
p a s s t h r u ()
. :
passthru ("dir c:\php"), .
.
,
. , d i r : \ p h p ,
rm / b i n / * d e l : \ * . * ! . , .
, d i r
I s , . ,
, . " . , ,
. d i r e c t o r y N a m e
S m i t h .
:
$directoryName = $_POST['directoryName'];
exec("mkdir $directoryName");
$ d i r e c t o r y N a m e S m i t h ,
e x e c ( " m k d i r $ d i r e c t o r y N a m e " ) S m i t h .
, .
, : S m i t n ;
rm *. $ d i r e c t o r y N a m e = S m i t h ; rm *
: m k d i r S m i t h ; rm *. , Unix/Lin JX,
, ..
m k d i r S m i t h ; rm *
mkdir Smith
rm *
. S m i t h ,
!
240
IV. -
, ,
. , .
, , . ,
,
.
nftofflo/ &TJ*
Internet.
, , ,
, . .
, Web- FTP.
Web- 11. FTP.
FTP Web. ,
, Web, . FTP
.
FTP /, ..
FTP,
.
FTP.
Windows FTP .
Unix/Linux/Mac
enable-ftp
.
FTP
, FTP
, f t p _ c o n n e c t {).
$connect = f t p _ c o n n e c t ( " j a n e t . v a l a d e . c o m " ) ;
- FTP.
$connect = f t p _ c o n n e c t ( " 1 7 2 . 1 7 . 2 0 4 . 2 " ) ;
FTP .
.
. Web- ,
anonymous, .
. ( . 8.)
FTP f t p _ l o g i n ().
, .
$ l o g i n _ r e s u l t = f t p _ l o g i n ( $ c o n n e c t , $ u s e r i d , $passwd);
FTP ,
:
Warning: ftp_login() expects parameter 1 to be resource, boolean given in
d : \ t e s t l \ t e s t l 3 . p h p on l i n e 9
13. PHP
241
, . , , ,
FTP.
:
$connect = f t p _ c o n n e c t ( " j a n e t . v a l a d e . c o m " )
or die("He ");
$login_result = ftp_login($connect,$userid,$passwd)
or die("He ");
d i e () .
FTP ,
.
.
FTP
. f t p _ n l i s t (),
. :
$filesArr = ftp_nlist($connect, "data");
f t p _ n l i s t () .
, :
$directory_name = ftp_pwd($connect);
$ f i l e s A r r = f t p _ n l i s t ( $ c o n n e c t , $directory_name);
; t
foreach($filesArr as $value)
{
echo $value\n;
}
FTP
FTP ] ta f t p _ g e t (). :
f t p _ g e t ( $ c o n n e c t , " n e w f i l e . t x t " , " d a t a . t x t " , FTP_ASCII);
n e w f i l e . t x t , > , a d a t a . t x t ,
FTP.
: FTP_ASCII ( ASCII)
FTP_BINARY ( ). ,
. , ASCII,
. ,
f t p _ p u t ( ) . :
ftp_put($connect, " n e w f i l e . t x t " , " d a t a . t x t " , FTP_ASCII) , n e w f i l e . t x t , ja , a d a t a . t x t ,
FTP.
FTP
ftp_close():
ftp_close($connect);
242
IV. -
13.2 ,
. t x t .
FTP.
13.2. , FTP
<?php
/* : downloadFiles
* :
*
.txt
*/
$dir_name = "data/";
$connect = ftp_connect("janet.valade.com")
or die("He FTP-");
$login_result' = ftp_login($connect, $userID, $passwd)
or die("He FTP-");
$filesArr = ftp_nlist($connect,$dir_name);
foreach($filesArr as $value)
{
if(ereg("\.txt$'\ $value))
{
if(!file_exists($value))
{
else
{
..
'
ftp_close($connect);
?>
, $ f i l e s A r r . f o r e a c h
, . t x t .
, , .
, ,
.
FTP
FTP, ,
, .
. 13.2.
13.2. FTP
ftp_cdup($connect)
ftp_chdir($connect,
ftp_close($connect)
"_")
FTP
13.
243
. li'.l
f t p _ c o n n e c t ("_")
.
_
IP-
ftp_fget($connect,
$fh, " d a t a . t x t " , FTP_ASCII)
,
, $ f h .
( . 12.)
ftp_fput($connect, "new.txt",
$fh, FTP_ASCII)
/
$ f h FTP
ftp_get($connect, "d.txt",
"sr.txt", FTP_ASCII)
, ,
s r . t x t , ;
d . t x t
ftp_login
( $ c o n n e c t , $ u s e r I D , $password)
ftp_mdtm($connect, " f i l e n a m e . t x t " )
ftp_mkdir
F P
($ c o n n e c t ,
" _ )
ftp_nlist
(Sconnect,
"_")
,
,
ftp_put($connect, "d.txt",
" s r . t x t " , FTP_ASCII)
, s r . t x t
; d . t x t
ftp_pwd(Sconnect)
ftp_rename
($connect,
"_",
"_")
f t p _ r m d i r ( $ c o n n e c t , "_") ,
,
ftp_size($connect, "filename.txt")
ftp_systype($connect)
,
, Unix
/ ,(
Internet .
. , Web-
. ,
Web- , 1 . ,
I forgot my p a s s w o r d ( )
.
..
244
IV. -
.
,
.
,
, .
SMTP (Simple Mail
Transfer Protocol ).
, : ,
Internet,
SMTP.
.
,
,
.
,
, Internet
. :
mail.ispname.net
Linux/Unix
sendmail.
,
p h p . i n i .
:
[mail function]
; Win32.
SMTP = localhost
; Win32.
;sendmail_from = me@localhost.com
; Unix.
;
; ( : "sendmail -t - i " ) ;sendmail_path =
Windows .
. :
SMTP = mail.ispname.com
,
. :
sendmail_from = Janet@Valade.com
Unix.
. ,
- , .
13.
245
^SSSfc Unix.
'^SpP
s e n d m a i l / u s r / s b i n / s e n d m a i l / u s r / l i o /
s e n d m a i l . s e n d m a i l ,
. ,
Qmail / v a r / q m a i l / b i n / s e n d m a i l *
/var/qmail/bin/qmail-inject.
p h p . i n i ,
Web-.
m a i l
:
mail{, , ,
);
).
m a i l () :
S
( );
S (, );
S
( );
/
(,
).
:
$to = "janet@valade.com";
$subj = "";
$mess = " ";
$headers = "bcc:techsupport@mycompany.com\r\n";
$ m a i l s e n d = m a i l ( $ t o , $ s u b j , $mess, $ h e a d e r s ) ;
, < iro
$ t o . :
$to= "janet@valade.com,me@mycompany.com";
$ h e a d e r s
t e c h s u p p o r t @ m y c o m p a n y . c o m .
:
$header = ":tech@mycompany.com\r\nbcc:sales@mycompany.com";
m a i l () ,
, , .
m a i l () TRUE, ,
FALSE . , TRUE
, .
. ,
, ,
.
246
IV. -
. :
Content-disposition: attachment; filename=test.txt
,
t e s t . t x t . ,
( - ):
$to = "janet@valade.com";
$subj = " ";
$mess = <<< END
,
.
.
END;
$headers = "Content-disposition: attachment;
filename=test.txt\n";
$headers .= "cc:sales@mycompany.com\n";
$mailsend = mail($to,$subj,$mess,$headers);
: C o n t e n t - d i s p o s i t i o n .
$ h e a d e r s \.
\ \ .
. ,
. . 12.
. f i l e _ g e t _ c o n t e n t s ():
$mess = file_get_contents("_");
13.3 , .
13.3. ,
<?php
/* : mailTest
* :
*
.
*/
$filename = "mydata.txt";
$mess = file_get_contents($filename);
$to = "janet@valade.com";
$subj = " ";
$headers = "Content-disposition: attachment; filename=mydata.txt\n";
if(!$mailsend = mail($to, $subj, $mess, $headers))
{
echo " \";
}
else
{
f i l e _ g e t _ c o n t e n t s ()
$mess.
$headers.
13.
247
m a i l ( ) . , , .
, C o n t e n t - t y p e
:
Content-type: _
, _
t e x t / p l a i n ( ).
HTML t e x t / h t m l .
, ,
- .
C o n t e n t - t y p e :
image/gif
image/jpeg
audio/x-wav
audio/vnd.rn-realaudio
video/mpeg
video/avi
, , ,
. , RTF , Word
Excel . ,
, C o n t e n t - t y p e
a p p l i c a t i o n / o c t e t - s t r e a m .
,
.
$mess = c h u n k _ s p l i t ( b a s e 6 4 _ e n c o d e ( $ s t r i n g ) ) ;
$ s t r i n g ,
f r e a d ().
,
,
Content-Transfer-Encoding: base64
13.4 , {
( ) .
13.4.
<?php
/* : mailGraphic
* :
*
.
*/
$filename = "logo.gif";
$fh = fopen($filename, "rb");
$fileContent = fread($fh, filesize($filename));
fclose($fh) ,$mess = chunk_split(base64_encode($fileContent));
$to = "janet@valade.com";
$subj = " ";
$headers = "Content-disposition: attachment; filename=logo.gif\n";
$headers .= "Content-type: image/gif\n";
$headers .= "Content-Transfer-Encoding: base64\n",-
248
IV. PHP-
$mess. , ,
.
13.
249
14
>. ...
>
>
>
PEAR
PEAR
(core),
, (extension).
,
, ,
. , :
.
, .
.
. ,
. ,
(. 12).
, , , , , PEAR (PHP Extension
and Application Repository ).
.
fiacutufteuusL PHJ*
,
, .
-
. (,
, , .)
, , .
, ,
phpinf ( ) . ,
. , .
S BCMath. , ,
.
S calendar. ,
(, , ,
..) .
S . , .
S ctype. ,
(, ).
S ftp.
FTP. .
S odbc. , ODBC.
/ .
PCRE.
S session. .
S SQLite.
SQL.
S tokenizer. , ,
.
S wddx. ,
WDDX, XML
.
/ xml. , XML.
S zlib. , ,
g z i p .
,
. , ,
.
Windows
,
. Unix Linux
. .
, , ,
, .
disable-session
,
. .
Linux,
, . Web-
, , ,
. , ,
, .
Web- www. php. net.
, - ,
, .. ,
.
, . ,
, .
, .
14.
251
.
, . (
.) , , Linux, Unix Mac, .
Windows.
,
( ).
1. . d l l e x t
.
e x t : \ p h p \ e x t .
2. p h p . i n i
:
;extension=php_gd2.dll
I
3. .
, .
S . >
>.
, ODBC
. ( . 12)
S GD. ,
(
HTML). GD
, JPEG, GIF, PNG .
4.3.0,
GD, .
1
w i t h - g d 2 , ,
(.. =DIR).
S PDF. ,
PDF, ,
, .
S cURL.
, H'l'l'FS, Telnet, FTP, LDAP .
. ,
. ,
, ,
. (, Oracle
, Oracle
.)
.
. ,
Web- , , , .
,
252
IV. -
. ,
. , MySQL
l i b m y s q l . d l l ( MySQL 4.0 ) l i b m y s q l i . d l l ( MySQL 4.1
). ,
mysql () mysql i ().
. 14.1 , ,
, 12.
. d l l ,
p h p / e x t , php_. DIR ,
. , .
14.1.
dll
bzip2 Compression
/
bzip2
_bz2.dll
--with-bz2=DIR
ClibPDF
PDF
_cpdf.dll
with-cpdflib=DIR
Crack
_crack.dll
--with-crack=DIR
cURL
_curl.dll
--with-curl=DIR
Domxml
XML
_domxml.dll
--with-dom=DIR
FDF
PDF
_fdf.dll
- - w i t h - f d f tk=DIR
GD
_gd2.dll
--with-gd2
gettext
_gettext.dll
--with-gettext=DIR
iconv
_iconv.dll
--with-iconv=DIR
IMAP
IMAP
_imap.dll
--with-imap=DIR
JAVA
Java
_java.dll
--with-java=DIR
LDAP
LDAP
_ldap.dll
--with-ldap=DIR
Multi-byte String
||nO_mbstring. d l l
)
Mcrypt Encryption
_mcrypt.dll
- - w i th-mcrypt=DIR
Mhash
..
_mhash.dll
--with-mhash=DIR
14.
--with-mbstring=LANG
253
. 14.1
dll
Mime type
_mime_magic.dll --with-mime_magic
Flash
_ming.dll
--with-ming
OpenSSL
_openssl.dll
--with-openssl=DIR
PDF
_pdf.dll
--with-pdflib=DIR
Printer
(
Windows)
_printer.dll
Shared Memory
_shmop.dll
--enable-shmop
SNMP
SNMP
_snmp.dll
--with-snmp=DIR
Sockets
_sockets.dll
--enable-sockets
XML-RPC
XML-RPC
_xmlrpc.dll
--with-xmlrpc=DIR
XSLT
XSLT
_xslt.dll
--enable-xslt
Zip Files
zip
_zip.dll
--with-zip.dll
, :
.
uioqtfUSL !*
PEAR (PHP Extension and Application Repository
PHP)
. , (
PEAR), PEAR ! \.
PEAR
(package). , ,
. , ,
, ,
PEAR.
.
, PEAR , )
"" , .
PEAR,
. PEAR , ,
. ,
254
IV. -
"" PEAR,
. PEAR
PEAR, .
PEAR
Web- PEAR ( h t t p : / / p e a r . p h p . n e t )
263 , .
.
f DB.
, .
S Net_Socket. Net Socket TCP.
S Net_SMTP. SMTP (Simple Mail Transfer
Protocol ) Net_Socket.
S Mail.
.
S XML_Parser. XML,
XML.
S PHPUnit. , .
PEAR/packages PEAR/go-pearbundle, .
ZIP.
PEAR, .
PEAR Web- PEAR
( p e a r . p h p . n e t ) .
.
: List Packages
( ) Search Packages ( ). List
Packages .
Authentication
Benchmarking
Caching
Configuration
Console
Database
Date and Time
Encryption
File Formats
File System
Gtk Components
HTML
HTTP
Images
Internationalization
Logging
14. PHP
Mail
Math
Networking
Numbers
Payment
PEAR
PHP
Processing
Science
Streams
Structures
Text
Tools and Utilities
Web Services
XML
255
.
, .
, Dependencies () ,
. Download ()
, . ,
PEAR .
Search Packages ,
, , .
, .
. , :
.
Manual, Documentation ().
. IV. Packages ()
, , , , .
.
Web- PEAR ,
PEAR .
, .
PEAR
PEAR (package manager),
.
PEAR , .
, , ,
.
PEAR
PEAR
. PEAR,
p e a r . php .
pear, . :
, p e a r l i s t - a l l . ( >
, Internet.)
4.3.0 PEAR
. Web- g o - p e a r . n e t
, ..
PEAR Windows
ZIP
PEAR . < Windows .
1. PEAR. ZIP,
Windows, .
, : \ p h p \ p e a r .
, ,
256
IV. -
PEAR . .
2. PEAR .
p h p . i n i :
include_path = ".; c:\php\includes; c:\php\pear"
, PEAR,
.
3. PEAR. go-pear .php
( g o - p e a r . b a t ) , .
:
Welcome t o g o - p e a r !
Go-pear w i l l i n s t a l l t h e ' p e a r ' command and a l l t h e f i l e s
needed by i t . T h i s command i s your t o o l f o r PEAR i n s t a l l a t i o n
and m a i n t e n a n c e .
Go-pear a l s o l e t s you download and i n s t a l l t h e PEAR p a c k a g e s
b u n d l e d w i t h PHP: DB, N e t _ S o c k e t , Net_SM.PT, M a i l , XML_Parser,
PHPUnit.
If you wish t o a b o r t , p r e s s C o n t r o l - C now, or p r e s s E n t e r :
( g o - p e a r !
Go-pear ' p e a r ' .
' p e a r '
PEAR.
Go-pear PEAR
: DB, Net_Socket, Net_SMPT, M a i l , XML_Parser, PHPUnit.
<Ctrl-C> E n t e r : )
, PEAR
. ,
.
g o - p e a r . b a t ,
CLI.
/ c l i . ,
Set PHP_BIN = cli/php.exe
g o - p e a r .
.
PEAR ( PEAR)
p e a r . b a t .
p e a r , .
, p e a r l i s t - a l l . (
, Internet.)
14.
257
l i s t - a l l PEAR.
, , .
PEAR
PEAR
PEAR (. ).
l i s t - a l l p e a r . b a t .
, , PEAR.
PEAR (
: \php):
pear i n s t a l l _
PEAR
Web- PEAR . , Mail,
pear i n s t a l l Mail
:
downloading Mail-1..2.tgz ...
...done: 12,287 bytes
requires package 'Net_SMTP'
Mail: dependencies failed
( Mail-1.0.2.tgz ...
...: 12,287
'Net_SMTP'
Mail: . )
, Mail .
Net_SMTP, .
Mail . PEAR
Net_SMTP, Mail.
PEAR Mail,
,
Mail a l r e a d y i n s t a l l e d
( Mail )
,
:
pear l i s t
pear update Mail
:
downloading M a i l - 1 . . 2 . t g z . . .
. . . d o n e : 12,287 b y t e s
upgrade t o a newer v e r s i o n ( 1 . 0 . 2 i s not newer t h a t 1.0.2)
( Mail-1.0.2.tgz ...
...: 12,287
(1.0.2
' ) )
258
IV. -
\
PEAR Internet,
:
Connection t o p e a r . p h p . n e t : 8 0 f a i l e d
( p e a r . p h p . n e t : 8 0 )
PEAR
pear u n i n s t a l l Mail
:
u n i n s t a l l ok: Mail
( Mail )
PEAR
PEAR .
PEAR
PEAR . php,
. , Mail
Mai 1. php. ,
. :
reqiure_once("Mail.php");
r e q i u r e _ o n c e () . , Mail .php . -,
, .
PEAR Web- PEAR.
DB PEAR.
PEAR
.
DB.
: PEAR - DB
DB
. 12 ,
, mysql_connect () pg_connect ().
.
. ,
MySQL.
: " Oracle,
". ,
, MySQL,
Oracle. ,
. .
,
, .
, .
14.
259
PEAR DB , 12.
1. .
2. .
3. , .
, ,
, .. ,
, DSN (Data Source Name). , DB
. :
$host = " l o c a l h o s t " ;
$dbuser = "admin";
Sdbpasswd = " s e c r e t " ;
$dbname = " S a l e s " ;
$dbtype "mysql";
$dsn = "$dbtype: /7$dbuser:$dbpasswd9$host/$dbname";
$dsn ,
.
$db = DB::connect($dsn);
SQL- .
:
$sql = "SELECT * from Sales";
$result $db->query($sql);
SQL- ,
$row = $result->fetchRow(DB_FETCHMODE_ASSOC);
fetchRowO
SQL- , .
,
$dbtype. - .
,
, . PEAR DB
.
V
*
S
S
S
/
S
S
S
mysql (MySQL)
p g s q l (PostgreSQL)
i b a s e (InterBase)
msql (Mini SQL)
mssql (Microsoft SQL Server)
o c i 8 (Oracle 7, 8, 81)
odbc(ODBC)
s y b a s e (Sybase)
i f x (Informix)
f b s q l (FrontBase)
IV. -
12 , .
, .
, .
DB i s E r r o r O .
: TRUE, .
getMessage ().
:
$db = DB::connect($dsn);
i f (DB::isError($db))
{
die($db->getMessage() ) ;
}
i s E r r o r ()
$db. TRUE, .. ,
i f . $db ,
d i e (), ,
i s E r r o r ( ) . ,
DSN, :
DB E r r o r : no such d a t a b a s e
( DB: )
14.1 , ,
. 12
PostgreSQL.
PEAR DB.
14.1. ,
<?php
/* : DisplayCustomers
* :
*
*
Web-.
*/
require_once("DB.php"); # PEAR DB
$host = "localhost";
$dbuser = "admin";
$dbpasswd = "secret";
$dbname = "Sales";
$dbtype = "pgsql";
$dsn = "$dbtype://$dbuser:$dbpasswd@$host/$dbname";
$db = DB::connect($dsn);
if (DB::isError($db))
{
die($db->getMessage());
}
$sql = "SELECT * from Customer";
$result = $db->query($sql);
if (DB::isError($result))
{
die($result->getMessage());
14. PHP
261
echo "<html>
<head><title>CnncoK /tit lex/head>
<body>
<table width=\"100%\" border=\"0\">\n";
while($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
{
if (DB::isError($row))
{
die($row->getMessage());
}
echo "<tr>";
echo "<td>{$row['lastname']}, {$row['firstname']}</td>
<td>{$row['phone']}</td>";
echo "</tr>\n";
}
PEAR !
. PEAR ,
r e q u i r e _ o n c e ().
, PEAR
. -
.
. PEAR , ; .
262
IV. -
oju^itto&o&uHuil'
/ ...
,
. -,
. Web-,
.
, ,
, .
15
,
>
>
...
, , ,
. , .
, , ,
, , .
:
Otnciftnanue /
(;).
, .
:
$test = 1
echo $test;
,
,
:
/1,
[&
(==).
. :
, 2+2=4.
, . ,
, (,
if).
, :
$ t e s t = 0;
while ( $ t e s t = 0)
{
$test++;
}
,* nefieuieHHOU
, .
,
.
.
$ t e s t = 0;
while ( $ t e s t = 0)
{
$Test++;
}
, $Test $ t e s t .
OfftctffncfHue qoMiafia
($) .
, :
Parse error: p a r s e e r r o r in t e s t . p h p on l i n e 7
OUIUJKU,
, ,
. , :
$test = "<table width="100%">" ,-
( 100)
. 1 one]
, , , .
:
$test = "<table width= ' 100% ' >" ,-
266
V.
$test = "<table width=\"100%\">";
:
$ t e s t = "<table width='100%'>;
PHP
, (").
, ,
, ( ").
,
. 5
.
//
, h e a d e r (),
. .
:
<html>
<?php
header("Location: http://company.com");
?>
,
. , ,
. , h e a d e r () ,
.
, .
/
(0),
, (1).
.
:
$ t e s t = 1;
while ( $ t e s t <= 3)
{
$array[]=$test;
15. , ... 267
$test++;
}
echo $ a r r a y [ 3 ] ;
(
). , - .
.
$[0] = 1
$array[l] m 2
$[2] = 3
.. $ [ 3 ] .
onefiatnofioe PHJ*
i n c l u d e ()
, , ..
.
. f i l e l . inc, :
i f ( $ t e s t == 1)
echo "";
.
<?php
$ t e s t = 1;
include("filel.inc");
?>
,
. Web-
if ( $ t e s t == 1) echo "";
.. f i l e l . i n c HTML. ; , :
<?php
i f ( $ t e s t == 1)
echo "";
?>
/
,
. . :
if ( i s s e t ( $ t e s t )
. ,
,
, .
:
while ($test<=3)
{
if ($test2 != "")
{
if ($test3 > 4)
268
V.
echo "";
}
}
, , .
, ?
, , , ,
while,
if. .
:
while ($test<=3)
{
if
( $ t e s t 2 != "")
if
( $ t e s t 3 > 4)
echo "";
} # if,
$test3
} # if,
} # while
J[lffnaHUl4,a
$ t e s t 2
ICfllfZMrtJlU U CpUZCfflHtxlMU
, ,
.
, , ,
. ( {.
.
16
Web-
/ uaie...
>
>
.
Internet .
. , .
Web-i/ PMJ*
Web-
, , .
www.php.net
fiaccbtuicu THJ*
,
, ( Lis :s).
, .
, ,
. ,
p h p - g e n e r a l ( , ), php-db (
), p h p - i n s t a l l (
), php-windows (
Windows) .. .
.
. ,
,
.
, .
www.php.net/mailing-lists.php
<&,qfio Zend
Zend . Web-
, , ,
.
http://zend.com
qua
Web-
www.phpbeginner.com
Web-i/ .cont
Web- .
, , ,
Windows Linux/Unix.
www.phpmac.com
Tec/atafLofiM PHJ*
Web-
(IDE Integrated Development Environment) .
105 ,
. .
http://phpeditors.linuxbackup.co.uk
271
ftechuatfLnbte -
Web- Web- ,
. .
www.oinko.net/freephp
272
V.
VI
WOMOIMJM. ' ?
/3
Windows, Unix/Linux Mac Web-,
CLI (Command Line Interface).
Web-,
Web- Apache US (Microsoft Internet
Information Server), 90% Web-.
Web-
Web- www. php. n e t .
5. ,
.
i n s t a l l . t x t ,
.
aioqifusi ?
Unix/Clnux
Web- Apache
Web-, .
(
Apache CLI). .
, ,
. ,
.
, .
, ,
.
4!S2&
'<^
Linux.
Linux Web- Apache
, .
, Linux ,
RPM. ( -.)
RPM, .
, CLI ,
RPM .
, ,
.
, Linux RPM,
, .
.
.
Unix/Linux
Web- Apache
Web- . Unix/Linux
Apache . .
*.
Unix/Linux
5 Unix/Linux .
1. Web- www. php. n e t .
2. Downloads.
276
VI.
3. .
5.0.0.
.
4. .
, .
5. ,
(, / u s r / s r c ) . Save.
6. ,
(, cd- / u s r / s r c ) .
, php-,
. t a r . gz .
, t a r . (
tarball.)
7. .
gunzip - php-5.0.0.tar.gz | tar -xf php-5 . 0 . 0 .
8. , .
cd p h p - 5 . 0 . 0
9. c o n f i g u r e .
. / c o n f i g u r e
.
Web- Apache, :
./configure --with-apxs
.
c o n f i g u r e ( ).
,
.
c o n f i g u r e ,
" Unix/Linux/Mac".
, apxs, ,
.
apxs (, f i n d /
-name apxs) w i t h - a p x s .
c o n f i g u r e :
./configure
--with-apxs=/usr/sbin/apxs
Web- Apache 2
apxs 2.
10. make.
.
277
.
make. .
PHP, CGI . I HP
Web- Apache l i b p h p 5 . so. ,
PHPCLI php, (,
u s e r / l o c a l / p h p ) . - ,
configure, ,
" Unix/Linux/Mac".
11. make i n s t a l l .
. , Web
Apache (, / u s r / l o c a l / a p a c h e / l i b e x e c / l i b p h p 5 . so).
Apache
apxs . ,
. apxs ,
. .
1. Web- www. php . n e t .
2. Downloads.
3. .
5.0.0.
.
4. .
, , 1.
5. ,
(, / u s r / s r c / p h p ) . Save.
6. ,
(, cd- / u s r / s r c / p h p ) .
php-,
. t a r . gz.
7. .
gunzip - php-5.0.0.tar.gz | tar -xf p h p - 5 . 0 . 0 c .
8. 1-5 ,
Web- Apache. , .
Apache h t t p d . a p a c h e . org.
Apache 1.3.27.
.
278
VI.
Web- Apache 2
. ,
, Web- .
9. Apache.
g u n z i p a p a c h e _ l . 3 . 2 7 . t a r . gz | t a r -xf
php-5 . . apache_l . 3 . 2 7 .
10. cd a p a c h e _ l . 3 . 27.
11. . / c o n f i g u r e .
. ,
Web- Apache,
.
.
. / c o n f i g u r e .
12. cd . . / p h p - 5 . 0 . 5 .
13.
./configure --with-apache=../apache_l.3.27
,
(\).
, c o n f i g u r e
. , "
Unix/Linux/Mac".
14. make.
. make
( ).
15. make i n s t a l l .
.
16. cd . . / a p a c h e _ l . 3 . 2 7
Apache.
17. Web- Apache
. / c o n f i g u r e --prefix=/www - - a c t i v a t e - m o d u l e = s r c / m o d u l e s / p h p 5 /
libphp5.a
,
. .
.
18. make.
. make (
).
, , , Apache
, .
.
279
Apache.
, ;. a p a c h e c t l b i n
Apache, / u s r / l o c a l /apache/bin, / s b i n /usr/sb:.n.
(, / e t c / r e d / i n i t . d ) . Apache
a p a c h e c t l s t o p .
h t t p d , . 18.
,
apache, / u s r / s r c / p h p / a p a c h e _ l . 3 . 2 7 / b i n / h t t p d .
h t t p d , .
/ u s r / l o c a l / a p a c h e / b i n , / s b i n
/usr/sbin.
.
h t t p d .
, . . \ .
lA&ac
4.3 ,
Unix/Linux. Web Apache ( Web-),
.
, Web CLI. .
, , . ,
. ,
.
, , .
Web- Apache
Web- .
Apache .
.
280
VI.
.
1. Web- (www. php. net).
2. Downloads.
3. .
5.0.0.
.
4. .
, .
5. ,
(, / u s r / s r c ) , Save.
6. ,
(, cd- / u s r / s r c ) .
, php-,
. t a r . gz ,
Stuffit Expander.
php- 5.O.O. , 8.
.
281
7. .
t a r xvfz p h p - 5 . . . t a r . gz
php-5 . . .
8. , .
, ,
cd p h p - 5 . 0 . 0
9. c o n f i g u r e .
. / c o n f i g u r e
, .
.
, ,
. :
--prefix=/usr
--sysconfdir=/etc
--localstatedir=/var
--mandir=/usr/share/man
z l i b : - - w i t h - z l i b .
Apache.
Web- Apache, w i t h - a p x s .
,
c o n f i g u r e :
./configure --prefix=/usr --sysconfdir=/etc
- - l o c a l s t a t e d i r = / v a r --mandir=/usr/share/man
with-apxs
, i (\).
.
( ).
J0*
, apxs, ,
.
apxs (, f i nd
/ -name apxs) w i t h - a p x s (-with-apxs=/usr/sbin/apxs).
282
VI.
p r e f ix=PRFF/X
i n f odir=D?
mandir=D/fl
PREFIX .
PflEF/X=/usr/local
/.
DIR=PREFIX/ i n f o
/.
DIR=PREFIX/man
w i t h - c o n f i g - f ile-path=D/fl
/,
php. i n i .
. D//?=/usr/local/lib
disabie-cgi
disable-cli
disable-libxml
enable-debugger
enable- ftp
enable-url-include
CGI
CU
XML
FTP
i n c l u d e ()
HTTP FTP, i n c l u d e
283
4.1
with-msql=DW
with-mysql=D/f?
with-mysqli=D/R
with-openssl=DOT
OpenSSL .
OpenSSL 0.9.5
with-oracle=D/fl
Oracle. DIR
, O R A C L E _ H O M E
with-pgsql =DIR
PostgreSQL DIR
PostgreSQL.
/usr/local/pgsql
with-servlet=D/fl
. DIR
JSDK. Java
dll-
with-xml
XML
Apache
Unix/Linux/Mac
p h p . i n i ,
, .
/ u s r / l o c a l / l i b / p h p . i n i . , ,
. ;
php. i n i , , .
php. i n i .
php. i n i - d i s t ( )
. p h p . i n i - d i s t ,
p h p . i n i - d i s t / u s r / l o c a l / l i b / p h p . i n i
sudo cp p h p . i n i - d i s t / u s r / l o c a l / l i b / p h p . i n i
Mac.
php. i n i , :,
, ?.
,
, . ,
php. i n i
.
4.
284
VI.
285
!!*/
p h p . i n i Web-cepeip
Apache .
? cuaneuie Windows
Windows 98/ ( ) Windows NT/2000/XP. Web ( CGI) Web-
(PHPCLI).
. .
Windows : ,
, , . z i p .
, .
.
S
CGI. ,
. , ODBC
( MS Access) SQlite,
. (
12.)
XML,
FTP .
CLI.
.
Web-, CLI .
HTML
HTML-.
ODBC.
.
S .
. z i p . , ,
.
.
(,
CLI ),
. . z i p .
14.
286
VI.
PHP CGI
Windows, Web-. ,
PHP CLI .
1.
2. Downloads.
3. Windows Binaries. ,
(
5.0.0).
4. Web-,
. Web-, .
.
5. .
,
.
6. , ,
Save.
, .
php,
- i n s t a l l e r . e x e , p h p 5 . 0 . 0 - i n s t a l l e r . e x e .
7. Web- ( IIS (Internet Informa
tion Server) PWS (Personal Web Server)), .
8.
(php5 . 0 . -installer. ).
, . .
,|'
itib*
. . 1. PHP
9. Next.
.
10. I agree.
, .
.
287
MiaotoftPWSonNTWotklHlion
Ktemi
f~ None (or other server]-1 wa* configure the web server manually
<Back
1^'<;
15. Web-. ,
None.
16. Next.
Ready. ,
.
17. Next.
5.0.0
. . :,
Web-. , Web- Apache
, . ..
, Apache .
. , .
288
VI.
,
Apache ,
.
|>1 ('iiiilic|in.itiiiii
Soy. the sollwatetoutomabcafe contiguie
the Apache httpdcont has not yet been
written. You will have to configure Apache
manually. See the php teadme tile tot nwe
OK
. A 3 .
Web Apache
5 Windows,
.
1. Web- www. php. n e t .
2. Downloads.
3. Windows Binaries
. z i p ( 5.0.0).
dZ&z^ib. . bz , ,
.
J / J j L x . , * > < ^ .
4. Web-,
. Web-, .
.
5. .
,
.
6. , ,
Save.
. php,
-Win32 . z i p , php-5 . 0 . 0-win32 . z i p .
7. zip- ,
, : \php.
zip- ,
, WinZip Pkzip.
,
.
289
, zip-
php-5 . . -Win32. :,
php. : \
: \php. ,
, PHP,
: \php.
, ,
Program F i l e s / P H P . - .
.
8. p h p . ,
PHPCLI.
.
Web- Windows
].
, Web- , )
Web-.
.
Windows
p h p . i n i , pas . .
, -i.
php. i n i .
php. i n i - d i s t ( )
.
.
S windows ( Windows 98//)
S winnt ( Windows NT/2000)
(, 4.3), p h p . i n i , HJ .
Web- US . p h p . i n i :
;cgi.force_redirect = 1
0 (;) :
cgi.force_redirect = 0
(
) .
. p h p . i n i
. ,
. 4.
290
VI.
Web-
Web- ,
.
Web- US PWS ( IIS 6),
. Web- Apache
, .
Web- Apache
Web- Apache .
1. Web- h t t p d . conf.
2. StartoPrograms 1 ^Apach HTTP Serven=>Configure
Apache
Server* Edit
Configuration
(^* Apache
HTTP
Serven=>Configure Apache ServeroEdit Configuration).
3. - ,
.
conf Apache (, : \Program F i l e s \ A p a c h e
g r o u p \ A p a c h e \ c o n f ) . ,
Notepad WordPad.
4. h t t p d . c o n f ,
.
.
S c r i p t A l i a s . S c r i p t A l i a s -
, . h t t p d . conf
S c r i p t A l i a s . ,
. ,
( ):
ScriptAlias /php/ "c:/php/"
(/php/),
(: /php/).
Action. A c t i o n
a p p l i c a t i o n / x - h t t p d - p h p p h p - c g i . e x e .
( ,
):
Action a p p l i c a t i o n / x - h t t p d - p h p
"/php/php-cgi.exe"
, -,
S c r i p t A l i a s .
S c r i p t A l i a s Apache p h p - c g i . exe .
(/). Web- Apache
.
5. h t t p d . conf ,
.
291
h t t p d . c o n f AddType. (
.) , .
AddType a p p l i c a t i o n / x - h t t p d - p h p .php
. (#), .
. php Web- Apache . .
6. Web-.
Windows NT/2000/XP Starts Programs1* Apach
HTTP Server=J>Control Apache Server (^1*Apache HTTP Servers
Control Apache Server) Web- .
Windows 98/ Starts Programs1* Apach Web Servers
Management (^"* Apach Web Server^Management).
.
Apache, . ;
. -
, .
IIS
,
IIS- 5 . : US . ,
IIS 6/Windows Server 2003 .
IIS- .
1. IIS.
Starts Programs'* Administrative Tools'* I nterret
Services Manager (^ ^
Internet) StartoSettingsoControl Panel*Administrative Tools*Internet
Services Manager (^ *>
1* Internet).
2. Web-.
3. Properties ().
4. Home Directory ( ).
5. Configuration ().
6. Mappings.
7. Add ().
8. Executable ,
c:\php\php-chi.exe.
9. Extension () . php.
.
10. Script Engine.
11. .
6-10, , (> , .phtml.
292
VI.
,
.
.
,
.
/ fiatfoffibi
.
array
(. 6).
: $ a r r a y = array{=>,
=>,
. . .) ;
=>,
array_count_values()
, .
: $ a r r a y _ o u t = a r r a y _ c o u n . t _ v a l u e s ( $ o r i g _ a r r a y ) ;
, $ o r i g _ a r r a y
$ o r i g _ a r r a y [ a ] =
$ o r i g _ a r r a y [ b ] =
$ o r i g _ a r r a y [ c J =
$ o r i g _ a r r a y [ d ] =
a r r a y _ c o u n t _ v a l u e s () $ a r r a y _ o u t
:
$array_out[] = 2
$array_out[] = 1
$array_out[] = 1
array_diff()
$1,
$2, $ .. (. 6).
:$array_out = a r r a y _ d i f f ( $ 1 , $2, $,
...);
array_intersect()
, .
:$simArarray = a r r a y _ i n t e r s e c t ( $ 1 , $2,
...);
_
()
$ o r i g _ a r r a y .
_, ,
_.
: $ a r r a y _ o u t = a r r a y _ k e y s ( $ o r i g _ a r r a y , "_");
, $ o r i g _ a r r a y
$ o r i g _ a r r a y [ a ] =
$ o r i g _ a r r a y [ b ] = OR
$ o r i g _ a r r a y [ ] = TX
$ a r r a y _ o u t :
$array_out[0] =
$array_out[1] = b
$array_out[2] =
_ OR, .. a r r a y _ k e y s () :
$array_out = a r r a y _ k e y s ( $ o r i g _ a r r a y , OR);
$ a r r a y _ o u t
$array_out[0] = b
array_merge ( )
.
,
(. 6).
: $bigArray = _ ( $ 1 , $2,
...);
array_merge_recursive
.
,
(. 6).
: $bigArray = array_merge_recursive {$1, $2, . . . I ;
_()
.
: $element = a r r a y _ p o p ( $ o r i g _ a r r a y ) ;
array_push()
.
: $new_size = a r r a y _ p u s h ( $ o r i g _ a r r a y , "2", "2",
"");
array_reverse()
$ o r i g _ a r r a y .
: $ a r r a y _ o u t = a r r a y r e v e r s e ( $ o r i g _ a r r a y ) ;
array_search()
$ o r i g _ a r r a y , ,
, FALSE.
: $key = a r r a y _ s e a r c h ( " " , $ o r i g _ a r r a y ) ;
294
VI.
array_slice()
$subArray $ o r i g _ a r r a y ,
(. 6).
: $subArray = a r r a y _ s l i c e ( $ o r i g _ a r r a y , ,
);
array_sum()
(. 6).
: $ sum = a r r a y _ s u m ( $ o r i g _ a r r a y ) ;
array_unique()
(. 6).
: $ a r r a y _ o u t = a r r a y _ u n i q u e ( $ o r i g _ a r r a y ) ;
arsortO
$ o r i g _ a r r a y
(. 6).
: a r s o r t ( $ o r i g _ a r r a y ) ;
asort()
$ o r i g _ a r r a y (. 6).
: a s o r t ( $ o r i g _ a r r a y ) ;
compact()
($varl, $var2 ..).
, .
: $ a r r a y _ o u t = c o m p a c t ( $ v a r l , $ v a r 2 ,
...);
count()
$ o r i g _ a r r a y (. 6).
:$size = c o u n t ( $ o r i g _ a r r a y ) ;
current
()
$ (. 6).
: $value = c u r r e n t ( $ a r r a y ) ;
end ()
$ a r r a y (. 6.)
: $ v a l u e = e n d ( $ a r r a y ) ;
e x p l o d e ()
. sep (
) (. 6).
: $ a r r a y _ o u t = explode ("sep", $ s t r i n g ) ;
extract()
.
(. 6).
: e x t r a c t ( $ a r r a y ) ;
295
implode()
, , sep (. 6).
: $ s t r i n g e x p l o d e ( $ a r r a y ,
"sep");
in_array()
$. ,
TRUE, FALSE.
: $bool = i n _ a r r a y ( " " , $ a r r a y ) ;
key ()
$ a r r a y .
: $key = key ( $ a r r a y ) ,-
key_exists()
$. ,
TRUE, FALSE.
: $bool = k e y _ e x i s t s ( " " , $ a r r a y ) ;
ksort,
krsort()
. k s o r t ()
, k r s o r t () (. 6).
:ksort($array); k r s o r t ( $ a r r a y ) ;
tsort(),
natcasesort()
"" . ,
n l , 2, 12, 25, n l , 12, 2, 25,
. n a t c a s e s o r t () .
: n a t s o r t ( $ a r r a y ) ; n a t c a s e s o r t ( $ a r r a y ) ;
next ()
$ (. 6).
: n e x t ( $ a r r a y ) ;
prev()
$ (. ().
: p r e v ( $ a r r a y ) ;
range ()
. ! 1
(, 1-10) ( - - ) .
:$array_out = r a n g e [ ,
);
reset()
$ (. 6).
: r e s e t ( $ a r r a y ) ;
sizeofO
$ (. 6).
:$size = s i z e o f ( $ a r r a y ) ;
296
VI.
/ ftarfotnu /
.
check.da.te ( )
TRUE, , FALSE .
:checkdate(, , ) ;
date ,
gmdate()
, $timestamp Unix,
. gmdate ()
.
: $ f o r m a t t e d _ d a t e = d a t e ("", $ t i m e s t a m p ) ;
getdatei)
, , , , ..,
$timestamp Unix.
: $ a r r a y _ d a t e = g e t d a t e ( $ t i m e s t a m p ) ;
localtime()
, , , , ..,
.
: $ a r r a y _ d a t e = l o c a l t i m e ( $ t i m e s t a m p ) ;
microtime()
, 1 1970 .
: $time_out = m i c r o t i m e O ;
mktimeO,
gmmktime()
Unix . gmmktime ()
(. 5).
: $timestamp = mktime(4acbi, , , , , );
t i m e ;
Unix (. 5).
: $ t i m e s tamp = t i m e ;
(ptfMJcuuu fiaJotnbi
.
basename()
(. 13).
: $filename = basename ("") ;
297
cbdirO
__
: c h d i r (" __") ;
(. 13).
chgrpl)
, .
: c h g r p (" __",
" ")
cbmod()
.
: chmod("__",
"_") ;
cbownO
.
: chown (" __",
" _")
closedirO
$dh (. 13).
: c l o s e d i r ($dh) ;
copy ()
(. 13).
: (" _",
" _") ;
dirnaiae ( )
(. 13).
: $ d i r e c t o r y _ n a m e = dirname("") ;
dis_total_space()
.
: $space = d i s _ t o t a l _ s p a c e ("") ;
diek_free_space()
.
: $f = d i s k _ f r e e _ s p a c e ("") ;
flose()
$fh (. 12).
: f c l o s e ( $ f h ) ;
feofO
TRUE $ fh (. II).
: feof ($fh) ;
fgetc()
() $f h -:
.
: $ c h a r = f g e t c ( $ f h ) ;
fgetcsv()
,
- sep (. 12).
: $ a r r a y _ o u t = f g e t c s v ( $ f h , ,
"sep");
298
VI.
fgets(),
fgetssO
$fh
. , f g e t s s () (. 12).
: $ l i n e = f g e t s ( $ f h , ); $ l i n e = f g e t s s ( $ f h ,
);
file
()
,
(. 12).
: a r r a y _ l i n e s = f i l e ( $ f h ) ;
file_exists()
(. 13).
: $bool = f ile_exists("__") ;
fileatimeO
(. 13).
: $timestamp = f i l e a t i m e ("__") ;
filectimeO
(. 13).
: $timestamp = filectime("__");
filemtimeO
(. 13).
: $timestamp = f i l e m t i m e ( " __") ;
flleownerO
- (. 13).
: $userID = f i l e o w n e r ("__") ;
f
()
, .
: $perms = f i l e p e r m s (" __")
fllesizeO
(. 13).
: $ s i z e = f i l e s i z e ( " _ _ " ) ;
filetypeO
, (. 13).
:$type = f i l e t y p e ( " _ - " ) ;
flock ()
(. 12).
: f ilelock("__") ;
fopen ()
(. 12).
: $fh = fopen (" __",
);
fput ()
. FALSE,
(. 12).
: $ r e s u l t = f p u t s ( $ f h , "",
);
.
299
fremdO
,
(. 13).
:$file_content = f r e a d ( $ f h ,
);
fscant()
. (
. 13.)
:$string = f s c a n f ( $ f h , "", $ v l , $v2, . . . ) ;
seek()
$f h .
: SEEK_SET ( ), SEEK_CUR ( ) SEEK_END ( ).
: f seek ($fh, , );
fwriteO
$f h.
(. 12).
: $ b y t e s _ w r i t t e n = f w r i t e ( $ f h , "",
);
getcwdO
, .
: $ c u r r e n t _ d i r e c t o r y = g e t c w d O ;
getlastmodO
.
: $timestamp = g e t l a s t m o d O ;
is_dir()
TRUE, , FALSE
(. 13).
: $bool = i s _ d i r ( "") ;
is_file()
TRUE, , FALSE
(. 13).
: $bool = i s _ f i l e ( "") ;
is_readable()
TRUE, ,
FALSE (. 13).
: $bool = i s _ r e a d a b l e ("__") ;
is_uploaded()
, Web .
:$bool = is_uploaded("__");
is_writable()
TRUE, __ { ,
FALSE (. 13).
: $bool = i s _ w r i t a b l e ( " __") ;
300
VI.
mkdlrO
,
.
: mkdir (" ___",
) ;
movm_\iploadmd_lle()
(. 11).
: move_uploaded_f i l e ( "_",
"");
opendir()
(. 13).
: $dh = o p e n d i r ("
__");
paasthru()
(. 13).
: p a s s t h r u (" _") ;
pathinfoO
,
: dirname (), basename ( ) e x t e n s i o n ().
: $ a r r a y _ d i r = p a t h i n f o f "") ;
readdirO
(. 13).
: $filename = r e a d d i r ($dh) ,readfilm()
.
. URL.
:$numberOfBytesRead = r e a d f i l e ( " _ _ " ) ;
rename
.
:rename("_",
"_");
rewind
$f h .
: rewind($fh) ;
rmdirO
(. 13).
: rmdir ("
__");
tmpfileO
,
.
: $fh = t m p f i l e O ;
touch()
. ,
. , .
: $bool = t o u c h (" __",
);
.
301
unmask ()
, ,
. .
: $old_mask= unmask () ;
unlink()
(. 13).
: u n l ink (" __")
/.fraJbifUrt /
HJT?
HTTP
.
tjbrowser
()
.
: $ s t r i n g = get_browser("") ;
get_meta_tags
()
,
<meta>, .
:$array_tags = get_meta_tags("__");
header()
HTTP Web- (. 10).
: h e a d e r (" _") ;
mail()
(. 13).
: $ s u c c e s s = m a i l ("",
" _",
"",
" ") ;
parse_url()
, URL-,
, , , ..
: $ a r r a y _ u r l = parse_url("aMpec_URL");
setcookie()
cookie (. 10).
: s e t c o o k i e ("",
"",
"",
_);
_,
"",
Uia/neyiariiuHecteue
. , cos
(), t a n () p i ( ), .
302
VI.
aba ()
.
: $ a b s o l u t e = abs () ;
blndecO
.
: $number_decimal = b i n d e c (_)
()
, .
: $number = () ;
floorO
.
: $ i n t = floor {) ;
bexdecO
.
: $number_decimal = h e x d e c ( ) ;
log()
.
: $ log = l o g {);
loglOO
10 .
: $ l o g l 0 = loglO {) ;
max ()
.
.
: $num_large = max($array) ; $num_large = max(1,
2, . . . ) ;
join ;
.
.
: $num_min = m i n ( $ a r r a y ) ; $num_min = m i n { 1 ,
!,
...) ;
number^format
()
-
. (.) (,) (. 5).
: $ f o r m a t t e d = number_format{,
"_",
"_");
octdecO
.
:$number_decimal = o c t d e c ( ) ;
POw()
, .
:$result = pow(,
);
.
303
rand ()
.
: $number_rand = rand(, );
round()
.
: $ r e s u l t = round{,
_);
aqrt ()
.
: $ s g u a r e _ r o o t = s g r t ();
arand()
.
: srand(_) ;
I;
gmtlaatmodO
.
: $timestamp = g e t l a s t m o d ( ) ;
ini_gat
()
.
: $ s t r i n g = i n i _ g e t ( " " ) ;
ini_set()
(. 4).
: i n i _ s e t ("", " ") ;
pbpinfoO
(. 4).
: phpinf ( ) ;
phpvmraionO
.
: $ v e r s i o n = p h p v e r s i o n O ;
putenvf)
.
_=
.
: p u t e n v (" ") ;
304
VI.
.
addBlaeheeO
/ , \ 0 .
:$string_escaped = a d d s l a s h e s ( " " ) ;
base64_encode,
base64_decode()
/ base64 (. 13).
: $ s t r i n g _ e n c o d e d = base64_encode("");
chop ()
.
:$chopped = chop("");
chr()
ASCII, .
: $char = c h r (KOUJUSCII) ;
count_chara()
,
$ s t r i n g , .
.. $ s t r i n g .
:$array = c o u n t _ c h a r s ( $ s t r i n g ,
);
mchoO
(. 3).
: echo !, 2, ,
...;
eregO,
eregiO
$ s t r i n g ,
. e r e g i () (. 7).
: $bool ereg("", $ s t r i n g ) ;
ereg_replace(),
eregi_replace()
$ s t r i n g , ,
. e r e g _ r e p l a c e ( ) ,
e r e g i _ r e p l a c e () (. 7).
:
$new_string
=
ereg_replace(ereg_replace("",
"_", $ s t r i n g ) ;
explode()
, $ s t r i n g ,
-.
: $ a r r a y _ o u t = explode ("", $ s t r i n g ) ;
htmlmntitima()
$ o r i g _ s t r i n g HTML .
: $ s t r i n g _ o u t = h t m l e n t i t i e s ( $ o r i g _ s t r i n g ) ;
5.
305
htmlspecialcbara
()
$ s t r i n g HTML, , ,
& &.
: $ s t r i n g _ o u t = h t m l s p e c i a l c h a r s ( $ s t r i n g ) ;
implode()
$ .
: $ s t r i n g _ o u t = implode ( $ a r r a y ,
"");
nl2br()
$ s t r i n g <br />
(\).
:$string_out = n l 2 b r ( $ s t r i n g ) ;
ord()
ASCII- .
: $ i n t e g e t = o r d ( " ") ;
parse_url
()
,
URL-.
: $ a r r a y = parse_url("anpec_URL");
print()
, .
: p r i n t ;
printfO
(. 5).
: p r i n t f ("", !, 2,
split
...;
splitiO
,
$ s t r i n g .
s p l i t i () .
: $ a r r a y = s p l i t ("", $ s t r i n g ) ;
$ a r r a y = s p l i t i ("",
$string);
sprintf
()
, (. 5).
: $ s t r i n g
= s p r i n t f ("",
1,
2,
, . . .) ;
str_pad()
$ s t r i n g .
: $ s t r i n g = s p r i n t f ( $ s t r i n g , ,
"");
str_repeat()
$ s t r i n g , .
: $ s t r i n g _ o u t = s t r _ r e p e a t ( $ s t r i n g ,
);
306
VI.
str_repla.ce
()
_ $ s t r i n g __.
: $ s t r i n g _ o u t = str_replace("_", "_",
$string);
strchrO,
strrchar
()
s t r c h r O $ s t r i n g ,
, a s t r r c h a r () .
:$string_part = s t r c h r ( $ s t r i n g ,
"");
strcmpl),
strcasecmp()
. $ s t r l $ s t r 2 ,
1, - 1 .
, 0. strcmp () ,
a s t r c a s e c m p () .
: s t r c a s e c m p ( $ s t r l , $ s t r 2 ) ;
strcapnO
$ s t r i n g .
: $ i n t = s t r c s p n ( $ s t r i n g ,
"");
strip_tasrs
()
$ s t r i n g HTML .
_
,
(. 10).
: $ s t r i n g _ s t r i p p e d = s t r i p _ t a g s ( $ s t r i n g ,
"_");
strlenO
$ s t r i n g .
: $ l e n g t h = s t r l e n ( $ s t r i n g ) ;
strposO,
strrpos()
s t r p o s ()
$ s t r i n g , a s t r r p o s () .
:$integer = s t r p o s ( $ s t r i n g ,
"");
$integer = strrpos($string,
"");
stratrO,
stristri)
$ s t r i n g ,
. s t r s t r () , s t r i s t r () .
:$str_part = s t r s t r ( $ s t r i n g ,
"");
$str_part = s t r i s t r ( $ s t r i n g ,
"");
strtolower(),
strtoupperO
$ s t r i n g .
: $ s t r _ l o w e r = s t r t o l o w e r ( $ s t r i n g ) ;
$str_upper = s t r t o u p p e r ( $ s t r i n g ) ;
307
mtrtrl)
$ s t r i n g _
_.
: $ s t r i n g _ o u t = s t r t r ( $ s t r i n g , "_",
"_");
subBtrO
$string
_.
: $ s t r i n g _ n e w = s u b s t r ( $ s t r i n g ,
,
_);
Bubatr_replace()
$ s t r i n g _
_.
: $ s t r i n g _ n e w = s u b s t r _ r e p l a c e ( $ s t r i n g ,
"_",
, _) ;
trlmO, ltrimO,
rtrimO
t r i m ( ) $ s t r i n g , l t r i m ( )
, a r t r i m () .
: $ s t r i n g _ n e w = t r i m ( $ s t r i n g ) ;
ucfirst()
$ s t r i n g .
: $ s t r i n g _ n e w = u c f i r s t ( $ s t r i n g ) ;
ucwordsO
$ s t r i n g .
: $ s t r i n g _ n e w = ucwords ( $ s t r i n g ) ;
wordwrap ()
$ s t r i n g (\\)
.
:$string_new = w o r d w r a p ( $ s t r i n g , _)
;
fia^OfHH
.
empty ()
, $varname - (. 7).
: $bool = empty ($varname) ;
g-et__de ined_classes
()
, (
).
: $ a r r a y _ c l a s s e s = get_def i n e d _ c l a s s e s () ;
gat_dafined_constant*()
.
308
VI.
: $ a r r a y _ c o n s t a n t s = g e t _ d e f i n e d _ c o n s t a n t s ( ) ;
Sret_defined
functions
()
.
: $ a r r a y _ f u n c t i o n s = g e t _ d e f i n e d _ f u n c t i o n s ( ) ;
get_defined_vare()
.
:$array_vars g e t _ d e f i n e d _ v a r s ( ) ;
issat
()
, $varname (. 7).
: $bool = i s s e t ($varname) ;
print_r()
$varname (. 4).
: p r i n t _ r ($varname) ;
putenvO
.
=.
: p u t e n v (" ") ;
_*
serialize()
.
. $ v a r i a b l e
, .
: $ s t r i n g _ s e r = s e r i a l i z e ( $ v a r i a b l e ) ;
unserialize()
.
: $ v a r i a b l e = u n s e r i a l i z e ( $ s t r i n g _ s e r ) ;
set()
$varname (. 4).
: u n s e t ($varname) ;
var_dvmp()
(. 4).
: var_dump ($varname) ;
309
Emacs, 41
Embedded scripting language, 25
Error message, 67
Exception, 27
Extension, 250
Access, 24
Apache, 34; 275
Arachnophilia, 41
ASCII-, 115
Attribute, 149
BBEdit, 41
BCMath, 250
C, 24; 60
Character string, 78
Class, 149
CLI, 39
Client-side language, 22
Command Line Interface (CLI), 46
Complex statement, 44
Concatenation, 81
Condition, 114
Conditional statement, 114; 121
Constructor, 154
cookie, 191
Core, 250
CSV, 213
ctype, 251
cURL, 252
D
Data Source Name (DSN), 260
Database, 216
Management System (DBMS), 216
dBASE, 23
Directory, 231
handle, 235
Domain name, 33
Dreamweaver MX, 42
E
E_ALL, 66
EditPlus, 41
File, 231
handle, 209
Transfer Protocol (FTP), 30
filePro, 24
Flat file, 27
Folder, 231
FrontBase, 24
FY?, 241
Function, 138
GET, 178
H
heredoc-, 78
Hidden field, 195
HomeSite, 41
HTML-Kit, 41
HTML-, 170
Hypertext Preprocessing, 21
IBM DB2, 24
IIS, 275
\
Infinite loop, 131
Informix, 23
Ingres, 23
Inheritance, 150
Instantiation, 152; 157
Integrated Development Environment (IDE), A 0
InterBase, 24
Internet Information Server (IIS), 35
IPlanet, 35
IP-, 33
J
Java, 60
JavaScript, 22; 205
PHPUnit, 255
-, 43; 113
Polymorphism, 151
POST, 178
PostgreSQL, 23
Property, 149
PWS, 291
Key, 89
Komodo, 42
Q
L
Query, 220
localhost, 222
Loop, 114
R
M
Maguma, 42
Master class, 150
Method, 149
Microsoft SQL Server, 23
mSQL, 23
Multiple inheritance, 151
MySQL, 23; 259
N
Nesting, 124
Net_SMTP, 255
Netscape Enterprise Server, 35
Notice, 67
Object, 148
Open Database Connectivity (ODBC), 24; 216
Oracle, 23
Output statement, 49
P
Package manager, 256
Parent class, 150
Passing by reference, 144
PEAR (PHP Extension and Application
Repository), 250; 254
Perl, 24
Personal Home Page, 21
PHP
CGI, 39
CLI, 25; 27; 275
PHPEdit, 42
s
Secure Sockets Layer (SSL), 35; 170
Server-side language, 22
Session, 195; 207
ID, 195
Shell script, 24
Simple
Mail Transfer Protocol (SMTP), 245
statement, 43
SQLite, , 27; 208; 229; 251
Structured Query Language (SQL), 220
Stuffit Expander, 281
Subclass, 150
Subdomain, 33
Sybase, 23
T
TextWrangler, 41
timestamp, 85
tokenizer, 251
TSV, 214
Type casting, 73
V
Validating information, 179
Variable, 57
311
w
Warning message, 67
WDDX, 251
Web-, 29
Web-, 21
Web-, 25; 26; 29
whois, 34
World Wide Web (WWW), 25
X
XML_Parser, 255
z
Zend, 27
Studio, 42
zlib, 251
A
, 107
, 90
PHP, 250
, 149
maxlength, 174
, 135
, 124
, 53
, 140
, 66
, 161
, 140
312
, 248
<form>, 189
PHP, 45
, 235
, 209
include_path, 138
Indexes, 169
trans-sid, 196; 198
upload_tmp_dir, 201
, 52
, 32; 33
, 200
, 220
, 143
, 57
, 232
, 195
, 113
, 57
, 89
, 152; 157
, 40
, 41
, 25
CLI, 46
, 27; 161
, 79
, 231
, 149
Exception, 161
, 152
, 150
, 22
, 89
, 64
, 52; 53
, 81
, 63
E_ALL, 68
, 66
, 154
, 161
, 72
, 140
, 56; 89
$_1, 194
$_FILES, 201
$_GET, 192
$_SERVER, 107
$_SESSION, 196
, 107; 177
, 104
, 28
, 256
, 149; 154
clone(), 161
_destruct(), 162
, 158
, 178
, 104
, 151
mod_so, 276
PEAR, 254
, 150
, 150
Web-, 34
, 27
, 45
, 66; 147; 161
, 71
, 81
, 119
, 148
- ,
27; 148
, 149
, 159
, 43
break, 132
define, 63
echo, 43; 59; 62
foreach, 97
if, 121
switch, 124
, 49
, 43
, 44
, 114
, 24; 236
, 72
, 217
, 24
PEAR-DB, 259
, 259
, 231
, 141
, 144
, 57
$this, 154
, 62
-, 126
, 188
, 21
, 134
, 33
, 150
, 151
, 75
, 67
, 73
, 73
, 179
, 72
313
, 250
, 252
, 31
, 116; 180
, 41
, 33
, 150
, 149
, 191; 195; 207
, 22
Apache, 34
IIS, 35
iPlanet, 35
, 22
, 78
, 79
, 33
(), 216
, 195; 199
, 44
, 67
, 93
, 79; 117
, 189
, 72
, 28; 107
, 24; 47
, 78; 117
, 27; 208
, 72
, 116
, 67
, 162
, 96
, 67
, 68
, 114
, 114; 121
, 265
, 168
314
, 231
CSV, 213
httpd.conf, 38
php.ini, 38; 40; 48; 67
, 248
, 69
, 229
, 24
, 23; 194
, 82
, 86
, 138
date(), 86
die(), 71; 147
echoO, 73
emptyO, 179
ereg(), 119
exit(), 70
includeO, 135
mail(), 246
my_error_handler(), j \
number_format(), 77
print_r(), 59
printf(), 77
require(), 136
strtotimeO, 87
system(), 239
, 83
HTTP , 302
, 297
, 293
, 304
, 308
, 297
, 302
, 141
, 94
, 305
X
, 31
, 72
, 114; 125
do..while, 130
for, 126
, 131
XT
, 72
, 250
Zend, 270
JavaScript, 22
, 22
, 220
, 43
, 244
315
I 0!
THT5
qjL& "
BESTSELL1NG
BOOK
//TM
SERIES
( )
[ ]
4?*'
^*fn}
S. \
^ 1
, 2
,
(
)
()
ger?m
,
,
germ, gem
geam
g(er)m
germ
Gem, grem
j[er]m
gem,grm
germ, gel
31 erjm
gym, gum
g[a-c]m
b l d g [ l - 3 ] 4 bldg111,bldg132
bldg,bldg555
ge*m
gm, geeem
germ,grm
ge{5}m
(2,5)
geeeeem
aa, aaa, aaaa, 145aaaaa
geeeem, geeeeeem
1,a3
g\*m
g*m
gem, germ
(!
)
BESTS ELUNG
BOOK
SERIES
Scolors[] "";
Scolors [] = "";
Spaint ['house'] "";
S p a i n t P b a r n ' ] = ""
array Scolors ("",
"");
array Scolors array(5 >
"", "");
array Spaint = a r r a y ( " b a r n "
=> "", "house" >
"");
SpaintPhouse'H'tall']
"";
Spaintpbarn'jptall'] =
"";
S p a i n t P h o u s e ' ] ["short')
"";
SpaintPbarn'] ['short'] =
"";
J^^
Scolors[l) = ;
Scolors[2] - ;
Spaint[house ] ;
Spaint[barn) " ;
Scolors[l] = ;
Scolors[2] = ;
Scolors[5] ;
Scolors[6] ;
Spaint[barn] - ;
$paint[house ] = ;
$paint[house][tall]
;
$paint[barn][tall] =
;
$paint[house] [short]
;
Spaint[barn] [short] =
;
One/iauuu
""
===
,
?
>
,
?
>=
,
?
<
,
?
<=
,
?
!=
!==
nefieMHHbix !PH!P
($)
^5
^S
J
3
-
4J
^
5 ""
..
. .
.. , .
.. , .. ,
..
"".
101509, , . , . 43, . 1.
07.06.2005. 70X100/16.
Times. .
. . . 25,8. .-. . 18,72.
3000 . 1879.
" "
,
.
197110, -, ., 15.