Вы находитесь на странице: 1из 18

HYPERTEXT PRE-PROCESSOR

PHP: Hypertext Preprocessor (a recursive acronym, originally personal home page) is a general-purpose scripting language that was originally designed for web development to produce dynamic web pages

It was originally called Personal Home Page !ools when it was created in "##$ by %asmus &erdorf to 'eep trac' of who was loo'ing at his online resume( )id-"##*: !echnion students +ndi ,utmans and -eev .uras'i redesigned the PHP language engine and wrote some of the most popular PHP modules

If you are coming from a /, /00, Perl or 1ava bac'ground, learning PHP would probably be a piece of ca'e( In fact, you probably can get started writing your scripts almost immediately( we can escape H!)& using php tags(when option --enable-short-tags is enabled) : 23 .4)56PHP6./%IP!6H5%5 37

4ur first PHP script : 23 phpinfo()8 37 !his should print a nice H!)& table that contains information about the current PHP build including list of all enabled9disabled options(

Hello, PHP !
simple output : ( /,I .tyle ) 23 echo 2html7:n2head7:n29head7:n2body7:nHello world;2br7:n29body7:n29html7 8 37 simple output < : (embeded style) 2html7 2head729head7 2body7 23 Hello world; 372br7 29body7

Hello, PHP !
)ore ways of 5scaping from H!)& : PHP= style: 23php echo Hello world; 8 37 the 2script7 tag: 2script language> php 7 echo Hello world; 8 29script7

/*PHP Comments*/
23 99comment ? comment 9@ multi line comment (c00 style) @9 37

23 Ax > false8 Ax > true8

PHP $Variables
? boolean

Ax > "B8 ? decimal Ax > "($C8 ? Dloating point Ax > Bx"+8 ? hexadecimal Ax > mmm: ooEoo:n 8 ? string > mmm ooEoo 0return in the end of the line Ax > Emmm oo:Eoo:nE8 ? string > mmm ooEoo:n Ay > FAx ? %eference

AxG"H > "B ? array of decimals AxG name H > budi 8 ? associative arrays AarrGH > lalala 8 ? push lalala AxG<HG lala H > xx 8 ? two dimensional Aname > budi 8 Aanimals > array( dog >7 anIing , cat >7 'ucing )8 echo hello ; )y name is Aname and my dogEs name is AJanimalsGEdogEHK 8 37

Operator
0 +ddition - .ubtraction @ )ultiplication 9 Livision M )odulus F +nd N 4r O Por ( add string (li'e in perl) 22 .hift left 77 .hift right

Assignment Operator
23 Ax > Hello 8 Ax(> world; 8 Ax > "B8 Ax008 Ax @> C8 Ax > array(",=,<,$,"B)8 Ax > array( a >7 $ , i >7 " , e >7 = , later >7 lQr )8 37

Comparison Operator
Aa >> Ab 5Rual - !rue if Aa is eRual to Ab( Aa >>> Ab Identical - !rue if Aa is eRual to Ab, and they are of the same type( Aa ;> Ab Sot eRual - !rue if Aa is not eRual to Ab( Aa ;>> Ab Sot identical - !rue if Aa is not eRual to Ab, or they are not of the same type( Aa 2 Ab &ess than - !rue if Aa is strictly less than Ab( Aa 7 Ab ,reater than - !rue if Aa is strictly greater than Ab( Aa 2> Ab &ess than or eRual to - !rue if Aa is less than or eRual to Ab( Aa 7> Ab ,reater than or eRual to - !rue if Aa is greater than or eRual to Ab( the 3 operator - li'e the / operator: 23 echo (Ax>>B) 3 P value is Tero : P value is not Tero 8 37

Logical Operators

Aa and Ab !rue if both Aa and Ab are true( Aa or Ab !rue if either Aa or Ab is true( Aa xor Ab !rue if either Aa or Ab is true, but not both( ; Aa !rue if Aa is not true( Aa FF Ab !rue if both Aa and Ab are true( Aa NN Ab !rue if either Aa or Ab is true(

if: 23 if (Aa 7 Ab) J print a is bigger than b 8 Ab > Aa8 K 37 else: 23 if (Aa 7 Ab) J print a is bigger than b 8 K else J print a is S4! bigger than b 8 K 37

elseif: 23 if (Aa 7 Ab) J print a is bigger than b 8 K elseif (Aa >> Ab) J print a is eRual to b 8 K else J print a is smaller than b 8 K 37

Uhile: 23 Ai > "8 while (Ai 2> "B) J print Ai008 9@ the printed value would be Ai before the increment (post-increment) @9 K 37 do (( while: 23 Ai > B8 do J print Ai008 K while (Ai2 "B)8 37

23 9@ example " @9 for (Ai > "8 Ai 2> "B8 Ai00) J print Ai8 K 9@ example < @9 for (Ai > "88Ai00) J if (Ai 7 "B) J brea'8 K print Ai8 K 37

9@ example = @9 Ai > "8 for (88) J if (Ai 7 "B) J brea'8 K print Ai8 Ai008 K 9@ example $ @9 for (Ai > "8 Ai 2> "B8 print Ai, Ai00)8 37

Вам также может понравиться