PHP - PowerPoint PPT Presentation

About This Presentation
Title:

PHP

Description:

php ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 51
Provided by: san154
Category:
Tags: php | mysql

less

Transcript and Presenter's Notes

Title: PHP


1
PHP
Hypertext Preprocessor
  • ??????? ???????
  • ??????????
  • ?????????????????????

???? PHP ???????? Personal Home Page
2
????????????????
  • ??? Static ????????????????????????????????
    Upload ????????
  • ???????????????????? ???? HTML
  • ??? Dynamic ?????????????????????????????????????
  • CGI (Common Gateway Interface)
  • Perl
  • DHTML
  • ??????? Script ???? HTML
  • ASP PHP JSP ???

3
Web Server
  • ??????????? ???????
  • Client/Server
  • Server ?????????? ???????? Web Server
  • IIS (Internet Information Services)
  • PWS (Personal Web Server)
  • Apache
  • Browser
  • Internet Explorer
  • Netscape

4
????????????????? Internet
Response
Web Server
Request
Client
5
Static Web Pages
  • ?????????????????????????????
  • ????????????????????????????? ????????????????????
    ?????????????????????????????
  • ????????? Page ?????????????????????????

6
3. Web server locates .html file
1. Author Writes HTML
4. HTML stream (from .htm page) Returned to
browser
Web Server
5. Browser Processes HTML And displays Pages
Client
2. Client request Webpage
7
Dynamic Web Pages
  • ???????????????????? Static Web Pages
  • ?????????????? Script ???????? HTML tag
    ?????????????????????????? ??? ???????????????????
    ?????? ????
  • ????????????????????????
  • ?????????????????????????????????
  • ??????????????????????? Page ???

8
Script
  • ????????????????????????????????????????????????
    ?????? ????????????????????????????
  • Client-Side Script
  • ???????? Script ??? Browser ???? VBScript,
    JavaScript
  • Server-Side Script
  • ?????????????????????? Web Server ???? ASP , PHP
    ,JSP

9
Client-Side Script
3. HTML stream (from .htm page) Returned to
browser
2. Web Server lacate .htm File
4. Browser Process Client-side script
Web Server
5. Browser Processes HTML And displays Pages
Client
1. Client Request Webpage
10
Server-Side Script
3. Web server processes instruction to create HTML
2. Web server Instruction File
4. HTML Stream returned to Browser
Web Server
5. Browser Processes HTML And displays Pages
Client
1. Client Request Webpage
11
Scripting Language
  • PHP ????????????? scripting language
    ?????????????????????????????????????? ???????
    (script) ?????????????????????????????????????
    ?????????????????????????? JavaScript, Perl
    ???????
  • ????????? PHP ????????????????????????????????
    ??? PHP ?????????????????????????
    ?????????????????????????????? HTML
    ???????????????????????????????????????????????
    ?????????????????? PHP ???????????????????
    server-side ???? HTML-embedded scripting language
    ??????????????????????????????????????????????????
    ?????????????? Dynamic HTML ??????????????????????
    ??????????????????

12
????????????? PHP
  • ?????????
  • PHP ??????????????????? Sever ????????????????????
    ????????
  • PHP ????????????? UNIX,Linux,Windows ??????
  • ???????????? ????????? PHP ???????????? HTML
    ???????????????????????????????????
  • ????????????????????
  • ?????????? XML ????????
  • ???????????????????????
  • ?????????????????????????????????????????????????
    ?????????????????????? Scalar,Array,Associative
    array
  • ???????????????????????

13
??????? PHP ?????? Apache ????????? Web Server
  • ???????????????? Apache ???????????????? Appserv
    ???????? ???????????????? package
  • Appserv ??? ???????????????? Package ??????????
  • Apache Web Server
  • PHP Script Language
  • MySQL Database
  • phpMyAdmin Database Manager

14
??????? EditPlus ??????????????? Weberver
  • ??????????? Edit Plus ?????????????????
    Tools?Preferences
  • ?????????????? Tools
  • ?? Add ????????????????
  • ?? Edit ????????????????????
  • (?????????????????????????????????)
  • ???????????????? Host ???? IP
  • ????????? Folder ??????????
  • ????????????????????????

??????????????????? PHP ?????? CtrlB ??????????
15
Run ?????? http//localhost
16
?????????? Notepad ???? editor ??????????? PHP
?????????????????
sample.php
lthtmlgtlttitlegt????? Script ???lt/titlegtltbodygtlt?ph
p echo "????????????? PHP ???????????"?gt lt/bodygt
lt/htmlgt
?????????????????????????? C\AppServ\www
17
???????????? Comment ?????? PHP
  • ??????????????????????????????????????????????????
  • ???????????????????????? / ... / ??????????????
  • ???? // ???????????????? ???? ?????? shell
    script ????????????? // ??????????????????????????
    ????????????????? ???? ?????????????????????????
    ???????????
  • lt? comment a 41 // set a to 41. b 10
    // set b to 10. b a / add a to b /
    echo b." \n" ?gt

sample2.php
18
????????????? ?????? echo
  • ????????????
  • echo ??????????1,??????????1,??????????1,....

????????
lt?echo "Hello Word ltbrgt"echo "Hello PHP
Programming" echo ltbrgtecho "PHP
Programming" ?gt
sample3.php
19
??????????????????????
  • ??????????????????????????????????????????????????
    ???????????????????????? ????????????????????
    (variable) ???????????? PHP ?????????????????
    Perl ?????????????????????????? dollar ()
    ???????????????????????????????????? (data type)
    ????????????????????????? ????????
    ???????????????????????????????????
    ?????????????? ?????????????? ???????????????
    ???? ??????? ????????? ??????????????????????
    ???? ???????

20
??????????????????????
  • Integer ???????????? ?????????????? ?????????
    ?????? ???????????
  • Float ????????????????????????? ????????????
    ??????????????
  • String ??????????????? ??? ???????
  • Array ?????????????????? ???? ????????
  • Object ???????????????????????????????????????????
    ????
  • Class Object ???? FunctionType juggling
    ????????????????????????????????????????????????

21
??????????????? ??????
  • var-namevalue
  • ???????????????????????- ?????????????????????
    ??????????????????? A-Z,a-z- ????????????????
    255 ????????- ??????????????? ????????????-
    ????????????????????? ??????????????
    ????????????????????????? ??????????-
    ???????????????????????????????????????????????-
    ??????????????????? ?????????????????
    ???????????????????????

22
???????????????????
sample4.php
sample5.php
???????????????????????gettype(var-name) ?????
???????lt?a1234echo gettype(a)?gt
??????????????????????????????????????????isset(
var-name)???????????? lt? a1234 if
(isset(a)) echo "???????????????????"
else echo ??????????????????????" ?gt
23
???????????????????
??????????????????????????????????????empty(var
-name) lt? a1234if (empty(a))echo
"???????????????" elseecho
??????????????????" ?gt
sample6.php
24
??????????????????
  • 1.Integer ???????????????? ??????????????
    ????????? ?????? ???????????a123a-123

lt?a123b456cabecho c?gt
sample7.php
25
??????????????????(???)
  • 2. Float ????????????????????????? ????????????
    ??????????????
  • a1.23a-1.23

lt? a123.45 b456.78 cab echo
c?gt
sample8.php
26
??????????????????(???)
  • 3.String ??????????????? ??? ???????
  • a"PHP Programming"a"1234567890"

lt?a"PHP Programming"b"1234567890" echo
a.ltbrgt.b?gt
sample9.php
27
??????????????
  • ????????? \n ???????????????????????? ???? escape
    character ???????? (?????????????? ?????????????)
    ??????????????????????????? ????????????????
    ?????????????????????????? HTML
    ??????????????????????? \n ???????????????????????
    ???????? ltBRgt ?? HTML

Escaped characters \n newline \r carriage \t
horizontal tab \\ backslash \ dollar sign \"
double-quote percent
28
?????? Array
  • ???????????????????????????????????????
    ?????????????????????? ???? ????
    ????????????????? ???? ?????????
  • Arrary 1 ????
  • ???????????????
  • a5
  • ?????????? 6 ?????? a0,a1,a2,a3,a4,
    a5

a4 a0"Somchai"a1"Werachai"a2"S
urachai"a3"Adisorn"
29
???????? Constant
  • ??? ??????????????? ??????????????????????? ?
    ????? ?????????????????? ???????????????????? 2
    ?????????
  • 1.???????? PHP ?????????? ????????????????????????
    ??????????????

E_ERROR ????????????????? parse ???????????
E_WARNING ??????????????????? ?????????????
E_PARSE ??? parse ????????????????????? Program ??????????????????
E_NOTICE ???????????????????? ???????????????????????
_FILE_ ???????????????????????? ????????????????????????
_LINE_ ?????????????????????? ????????????????????????
PHP_VERSION ???? V. ??? PHP ?????????????
PHP_OS ???????????????????????????? Server
TRUE ??????????????
FALSE ??????????????
30
???????? Constant (???)
  • 2.???????????????????????????????????????????????
    ???? ????????????????????????
  • ??????define(Constant-name,Value)
  • ????? Constant-name ???? ??????????? Value
    ????????????????
  • ????
  • define("name",MANA TUDTU")echo name
  • define("old","21")define ("add",Phichit")

31
Operator ??? ????????????????????? ?
  • ?? PHP ???????????????????????????? 6
    ????????????????? ????????????????????????????????
    ??????????????????

1.Arithmetic Operators ?????????????????????????
2.String Operators ???????????????????????
3.Assignment Operators ????????????????????
4.Logical Operators ??????????????????????????
5.Comparison Operators ???????????????????????????
6.Operator Precedence ?????????????????-?????
32
Operator ??? ????????????????????? ? (???)
  • 1. Arithmetic Operators ?????????????????????????

???????? ???????? ???????
a b ??? ???????? a ??? b.
a - b ?? ?????????? b ???????? a.
a b ??? ???????? a ??? b.
a / b ??? ???????? a ??? b.
a b ????????? ??????????????? a ?????? b.
33
Operator ??? ????????????????????? ? (???)
  • 2. String Operators ???? ?????????????????????????
    ???????????? (.) ????? ?????????????????
  • ????????

sample10.php
lt?a "PHP"b "Programming"c
a.becho c?gt
Out Put PHPProgramming
34
Operator ??? ????????????????????? ? (???)
  • 3. Assignment Operators ????????????????????
  • ?????????????????????? "" ???????????????????????
    ??????????????????????????????????????????????????
    ?????????
  • a 3 a 5 // a 8, ????????????? a
    a 5 b "Hello "b . "There!" // b
    "Hello There!",????????? b b . "There!"

35
Assignment Operators(???)
??????????? ???????? ?????? ?????????????????? a2
???????? a1 1
???????? a 1 3
- ????? a - 1 1
?????? a 1 2
/ ?????? a / 1 2
36
Operator ??? ????????????????????? ? (???)
  • 4. Logical Operators ??????????????????????????

???????? ???????? ???????
a and b And ?????????????? a ??? b ????????
a or b Or ??????? a ???? b ?????????????????????
a xor b Or ??????? a ???? b ?????????????????????, ?????????????????????????????.
! a Not ??????? a ???????
a b And ???????? a ??? b ????????
a b Or ??????? a ???? b ?????????????????????
37
Operator ??? ????????????????????? ? (???)
  • 5. Comparison Operators ??????????????????????????
    ?

???????? ???????? ???????
a b ??????? ??????? a ???????????? b.
a ! b ?????????? ??????? a ??????????????? b.
a lt b ???????? ??????? a ?????????????b.
a gt b ??????? ??????? a ???????????? b.
a lt b ??????????????????? ??????? a ???????????????????????? b.
a gt b ?????????????????? ??????? a ??????????????????????? b.
38
Operator ??? ????????????????????? ? (???)
  • 6. Operator Precedence ?????????????????-?????????
    ?

???????????? ???????? ???????? ????????
???????????? 1 a ???? aa1 ???????????????????? a ??? 1
-- ??????? 1 a- ???? aa-1 ????????????????? a ??? 1
39
??????????????????????????????
  • 1. if...else ???????????? 2 ???????

lt? if (x 0) echo x echo " is
zero.ltBRgt\n" else if (x gt 0) echo
x echo " is positive.ltBRgt\n" else
echo x echo " is negative.ltBRgt\n"
?gt
sample11.php
lt?a 1if (a1) echo "a1 OK" ?gt
Out Put a1
40
?????????????????????????????? (???)
  • 2.if..elseif..else

lt?a 4if (a1) echo " a 1 OK "
elseif (a2) echo " a 2 OK" elseif
(a3) echo " a 3 OK "else echo "
a Not OK "?gt
Out Put a Not OK
sample12.php
41
?????????????????????????????? (???)
  • 3.switch case

lt?a 3switch (a)case 1 echo "a 1
OK" breakcase 2 echo "a 2
OK" breakcase 3 echo "a 3
OK" breakcase 4 echo "a 4
OK" breakdefault echo " a Not OK" ?gt
sample13.php
out Put a 3 OK
42
?????????????????????????????? (???)
  • 3.break
  • ?????? break ??? continue ????????????????????????
    ?????? ???????????????? PHP ???
  • 4.continue
  • ?????????????????????????????? ???
    ??????????????????????????????????????????????

43
?????????????????????????????? (???)
lt? for(i1 i lt10 i) if(i5)
continue if(i9)
break echo i ?gt
sample14.php
44
?????????????????????????????? (???)
  • 5. include?????? include ????????????????????????
    ??????????????????????????????????????????????????

sample15.php
file1.php
lt? include("file1.php") include("file2.inc") ?gt
Hello world 1ltBRgt
file2.inc
Hello world 2ltBRgt
45
?????????????????????????????? (???)
  • 6.redirect?????????????????????? Page
    ???????????????????????????header('Locationfile.
    php')
  • header('Location http//www.example.com/')
  • 7.or
  • ???????? OR???????????????? ????????????????????
    ?????????????????????? ???????????????????????????
    ????? ?????????????????

if ((name "") (named ""))
46
?????????????????????????????? (???)
  • 9.and
  • ??????????????????????????????????????????????
    ????????? ??????????????????????????
    ?????????????????

if ((name "") (named ""))
47
??????????????
  • for ?????????????????????????????
    ????????????????????

sample16.php
lt?for (a1alt5a) echo "ltfont
sizeagt ??????????????? ??????????????????? a5
ltbrgt "?gt
48
??????????????(???)
  • while
  • ??????????????????????????? ?????????????????????
    ?? ??????? ??????????????????????

sample17.php
lt?a1while (alt5)echo "ltfont sizeagt
??????????????? ??????????????????? a5 ltbrgt
"a?gt
49
??????????????(???)
  • do..while
  • ????????????????????????????? ???????????????????
    ??????????????????????

sample18.php
lt?a1do echo "ltfont sizeagt
??????????????? ??????????????????? a5 ltbrgt
"awhile(alt5)?gt
?????? do-while ???????????????????
?????????????????????? ???????????????????????????
????????????? ?????????????? while-do
???????????????????????????????
????????????????????????????????
??????????????????????????????? for-loop
????????????????????????
50
?????????
???????????????????????????????????? array
array ???? member ??????????????-??????? ????? 10
?? ??????????????????????????????????????
????? ????-???????
1 ????? ?????
2 ???????? ??????
3 ?????? ?????
4 ????? ?????
5 ??????? ??????
6 ?????? ???????
??? LOOP ??????????????? Array
??????...?????????????????? ????????? 5 ????????
????????????? ?????????????????
Write a Comment
User Comments (0)
About PowerShow.com