0% found this document useful (0 votes)
41 views4 pages

Operators Variable Management: PHP Quick Reference Card

PHP Quick Refference

Uploaded by

amrid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views4 pages

Operators Variable Management: PHP Quick Reference Card

PHP Quick Refference

Uploaded by

amrid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PHP Quick Reference Card

1.02
Copyright, 2008 BrandsPatch C
http!""###.e$p%ainth.at
Co%or key on Page &
Code Structure
'(php
)site = *+$p%ain,hat*-
function sayHello(){
)s = *He%%o fro. *-
echo )s-
""sing%e %ine co..ent
}
function sayHelloEx(){
)s = *He%%o fro. *-
global )site-
echo )s.)site-
"/Co..ent spanning
t#o or .ore %ines /"
}
sayHello();
print )site-
(0
Reusing Code
,he include, require, include_once and require_once
key#ords faci%itate the reuse of PHP code. 1or instance
include *.ycode.php*-
#ou%d cause the contents of .ycode.php to 2e .erged
into the current fi%e. 1ai%ure to find .ycode.php resu%ts in
a #arning. require 2eha3es si.i%ar%y 2ut thro#s a fata%
error. ,he #_once 3ersions pre3ent function redefinition.
Noenclature Rules
4%% %a2e%s
1
in PHP 2ear the for. )name. name can
consist of upper 5 %o#ercase %etters a67, e$tended
48C99 characters fro. 0$:1 to 0$11, the underscore
character, ; and nu.2ers. ,he first character cannot 2e
a nu.2er. <a.es are case sensiti3e. )this is a
predefined read on%y 3aria2%e used to refer to the
current o2=ect conte$t. ,here are no %i.its on na.e
%ength. <a.es are case sensiti3e.
1 8trings used to identify constants, functions, 3aria2%es 5 Heredoc
!isibilit" # Scope
>aria2%es in PHP genera%%y ha3e a sing%e scope ? i.e
they are a%#ays 3isi2%e. Ho#e3er, user defined functions
ha3e their o#n %oca% scoping conte$t ? i.e. do not ha3e
access to 3aria2%es defined outside the function. 4
reference to )site in sa"$ello #ou%d .ere%y create a
ne# e.pty %oca% 3aria2%e ca%%ed )site. ,o access such
3aria2%es do one of the fo%%o#ing
@se the global key#ord as in sa"$ello%& a2o3e.
@se the '()*+,)S array 6 '()*+,)S-*site*.
/ata 0"pes
PHP supports four sca%ar data types
2oo%ean 6 takes the 3a%ues ,R@+ 5 148+
integer 6 deci.a%, he$adeci.a% or octa%. e.g. A2, 0$20,
0&0. ,he constants PHP;9<,;B4C and
PHP;9<,;89D+ pro3ide p%atfor.6dependent
infor.ation. 9nteger o3erf%o# causes si%ent
transfor.ation of the 3aria2%e into a f%oat.
float 6 ,ypica%%y 9+++ E& 2it #ith 1& deci.a% digits.
string 6 sing%e 2yte character seFuence. 8ee 2e%o#.
>aria2%es that ha3e not 2een assigned a 3a%ue or ha3e
2een unset contain the specia% 3a%ue N1)). 4 N1))
assign.ent to an o2=ect 3aria2%e destroys the o2=ect.
+$p%icit typecasts are rare%y needed in PHP. 9f reFuired
use the code
)$ G (#))y- 6 #here H is one of 2oo%, f%oat, int or string.
*perators
*perator %&aple Result
I 234 A I 2 J
. *+$p%ain*.*,hatK* *+$p%ain,hatK*
" 254 A"2 1.J
L :L& A
G )i G 2 )i set to 2
)i G 2-
IG 23=4 )iIG1- A
s G *+$p%ain*-
.G s.G*,hatK* *+$p%ain,hatK*
GG
1
AGG*A*
AGGA
AGG2
true
true
fa%se
GGG
2
AGG*A*
AGGA
AGG2
fa%se
true
fa%se
KG or '0 *php*KG*PHP*
AKGA
true
fa%se
KGG AKGG*A* true
' 264 2 ' A true
'G 26=4 2'GA true
)i G 2-)= G J-
5 )i 5 )= 2
M )i M )= :
N )i N )= J
O O)i 6A
'' 2664 )i '' 1 &
II 2334 )iII
A
-II)i
&
A
)i G 2-)= G J
55 P)i 'G 2Q 55
P)= ' :Q
true
MM P)iL2 0 0Q MM P)=
L2 GG 0Q
fa%se
K P)iGG2Q 55 KP)=
L2 GG 0Q
true
1 ca%%ed loose co.parison- 2 ca%%ed strict co.parison
A e3a%uates after use & e3a%uates 2efore use
Constants
defineP)na.e,)3a%ue,-)ci.Q
is used to define a constant na.ed )na.e #ith the
sca%ar 3a%ue )3a%ue. Case insensiti3e if )ci G 0R1%.
constant references do not start #ith a '
constants cannot 2e a%tered
constants are g%o2a%%y accessi2%e
References to undefined constants are treated as string
%itera%s. PHP defines fi3e .agic constants #hose 3a%ue
depends on #here they are used
Nae /escription
;;9<+;; Current %ine nu.2er
;;19+;; Current fi%e na.e #ith path
;;R9R;; Path to current fi%e
;;C488;; Current c%ass na.e
;;B+,HSR;; Bethod na.e as class:methodname
Bagic constants in inc%uded fi%es are e3a%uated prior to
inc%usion.
!ariable 7anageent
8unction 9urpose Return !alue
ept" Check if e.pty( boolean
float:al Con3ert to f%oat float
get_defined_:ars ist a%% 3aria2%es arra"
gett"pe >erify data type string
1
int:al Con3ert to int integer
is_#
2
>erify data type boolean
seriali;e 8tringify for storage string
sett"pe
A
8et data type boolean
str:al Con3ert to string string
unseriali;e Regenerate fro.
string
boolean<
integer etc
unset
&
Restroy the 3ar 3
1 array, 2oo%ean, integer, dou2%e, string or o2=ect
2 H is one of array, 2oo%, f%oat, int, nu%%, o2=ect, sca%ar, string
A second para.eter is a string. 8ee note 1 a2o3e
& 2eha3ior inside a function depends on nature of 3aria2%e 2eing unset
,rra"s
4rrays are used to store seFuences of re%ated 3a%ues in
a ta2u%ar for.at. PHP has J #ays of defining an array
)%a.p G arra"()-
)%a.p-.=*9<@C*-)%a.p-.=*4pache*-
)%a.p-.=*By8Q*-)%a.p-.=*PHP*-
)%a.p G arra"P**G0*9<@C*,*4*G0*4pache*,
*B*G0*By8Q*,*P*G0*PHP*Q-
)%a.p G arra"P*9<@C*,*4pache*,
*By8Q*,*PHP*Q-
)%a.p G arra"()-
)%a.p-=.=*9<@C*-)%a.p->.=*4pache*-
)%a.p-?.=*By8Q*-)%a.p-@.=*PHP*-
1
)%a.p G arra"()-
)%a.p-**.=*9<@C*-)%a.p-*4*.=*4pache*-
)%a.p-*B*.=*By8Q*-)%a.p-*P*.=*PHP*-
PHP arrays can 2e associations ? i.e. a uniFue key, Pe.g.
** a2o3eQ is associated #ith each 3a%ue in the array. 1or
.u%tip%e di.ensions use arrays #ithin arrays.
,rra" 7anipulation
8unction /escription
arra"_change
_Ae"_case
TuessK
arra"_chunA()
arr,)si7e,U)fV)
Returns an array of arrays containing
)si7e e%e.ents each fro. )arr.
0R1% for )f preser3es keys.
arra_fill_Ae"s(
)keys,)3a%ues)
Create an associati3e array using
)keys, and )3a%ues,.
arra"_fill()star
t,)nu.,)3a%ue)
Create an array #ith )nu. e%e.ents
fro. inde$ )start fi%%ed #ith )3a%ue
arra"_flip()arr
)
1%ip 3a%ues and keys in )arr
arra"_Ae"_e&i Check for )key in )arr
1
PHP Quick Reference Card
1.02
sts()key,)arr)
arra"_re:erse(
)arr,U)fV)
Re3erses e%e.ent order. )f G 0R1%
preser3es keys.
arra"_:alues(
)arr)
Returns a%% 3a%ues in )arr in a
nu.erica%%y inde$ed array.
count()arr) Returns e%e.ent count
Asort()arr) 8orts array using keys
1By defau%t array indices start at 0. Here #e force the. to start at 1
/ate # 0ie
8unction /escription
get/ate(-)ti.e.) 4ssociati3e array #ith current
ti.e or )ti.e e$p%oded into
Be" !alue
seconds 06JW
.inutes 06JW
hours 062A
.day =PCQ6A1
#day 0P8unQ6EP8atQ
.on 1PCQ612
year e.g 2008
yday 0PCQ6AEJ
#eekday 8unday6
8aturday
.onth Xanuary6
Rece.2er
0 @<9C +poch
checAdateP).onth,
)day,)yearQ
>a%idates date for )year 2et#een
1 5 A2:E:
date()for.at,
-)ti.e.)
1or.ats current ti.e or 'tie
using 'forat.
8orat Char %&aple
/a"
d 016A1
= 16A1
R Bon
l(l.c. L) Bonday
< 1PBonQ
8 8uffi$es st, nd
etc. @se #ith =
# 0P8unQ
7 06AEJ
DeeA
Y Yeek of year
7onth
1 Xanuary
. 01612
B Xan
n 1612
t Rays in .onth
Eear
Peap ZearQ(
1!0
Z 2008
y 08
0ie
a a. or p.
4 4B or PB
g 1612
T 062A
h 01612
H 0062A
i PBinutesQ 006JW
sP8econdsQ 006JW
@ @<9C +poch
0ie;one
e +urope"Paris
P
to TB,
tie() @<9C +poch ti.e
%scape Sequences
Sequence 7eaning
[n inefeed, 0$04
[r Carriage Return, 0$0R
[t ,a2, 0$0W
[3 >ertica% ta2, 0$0B
[f 1or. feed, 0$0C
[[ Backs%ash
[) Ro%%ar sign
[\ Rou2%e Fuote
[$00 6 [$11 Char in he$adeci.a%
8ile S"ste
8unction /escription
basenae()fna.e,
-)suffi$.)
1i%ena.e .inus path ? and
e$tension if )suffi$ is pro3ided
file_e&ists()fna.e) Roes )fna.e e$ist( Yorks #ith
fi%es # fo%ders
filesi;e()fna.e) Tuess(
fileatie()fna.e) Yhen #as the fi%e accessed(
P@<9C ti.eQ
chod()fna.e,
).ode)
Change access rights to fi%e
)fna.e. ).ode is an octa%
nu.2er in the for.at 0STY
#here S G S#ner, T G @ser
group for S#ner 5 Y G the #or%d,
i.e. e3eryone e%se. 9ndi3idua%
digits are .ade up 2y adding the
desired rights as %isted 2e%o#
!alue Right
1 +$ecute
2 Yrite
& Read
e.g. 0E&& .eans read"#rite rights
for o#ner 5 =ust read for others.
pathinfo()fna.e, Returns associati3e array #ith
-)options.) keys *dirna.e*, *2asena.e*,
*e$tension* 5 *fi%ena.e*.
*R P4,H9<1S;H 6 H G
uppercase keys a2o3e 6 into
options for .ore se%ecti3e resu%ts.
dirnae()fna.eQ Counterpart of basenae a2o3e
glob()pattern,
-)f%ags.)
Returns array of a%% fi%ena.es
.atching )pattern. *R TSB;H
f%ags for .ore se%ecti3ity
H 8lag 9urpose
B4R] 4dd s%ash
<S8SR, 4s is %ist
BR4C+ +$pand ^a,2,c_
and .atch
S<ZR9R Sn%y fo%ders
+RR 8top on error
is_#()na.eQ
H G dir or fi%e
is )na.e a fo%der or a fi%e(
chdir()dna.eQ Change current directory. 148+
on fai%ure.
closedir()dhand%eQ C%oses directory opened ear%ier
using opendir.
getcFd() Tet current directory
Adir()dna.e,
-).ode,)recurse.)
Bakes directory )dna.e. ).ode
defau%ts to 0::: ? ignored on
Yindo#s. )recurse forces a%%
directories in )dna.e to 2e
created
opendir()dna.eQ Spens )dna.e and returns
hand%e.
readdir()dhand%eQ Reads ne$t fi%ena.e fro. open
directory.
reFinddir()dhand%
eQ
TuessK
rdir()dna.eQ 4tte.pts to de%ete )dna.e ?
su2=ect to per.issions. 148+
on fai%ure
scandirP)dna.e,
U)orderVQ
Returns array of fi%es in )dna.e.
Pro3ide )order G 1 for
descending na.e sort.
disA_free_space()
dna.e)
TuessK
renae()o%d,)ne#) TuessK
fclose()fhand%e) C%ose fopenGd fi%e
fopen()fna.e,
).ode)
=
Spens)fna.e. ).ode can 2e
7ode 7eaning
r
1
Read
rI
1
Read"Yrite
#
1,2,A
Yrite
#I
1,2,A
Read" Yrite
a
A,&
Yrite
aI
A,&
Read"Yrite
$
1,A,J
Yrite
$I
1,A,J
Read"Yrite
11i%e pointer at BS1 2,runcate fi%e to 7ero
%ength ACreate fi%e if reFuired &1i%e pointer
2
PHP Quick Reference Card
1.02
at +S1 J1ai% if fi%e a%ready e$ists
8pecify an additiona% b P2inaryQ,
e.g. *#2* for a%% #rite .odes to
pre3ent CR"1 character
trans%ation. 4%#ays specify b #ith
a%% 2inary fi%es, e.g. i.ages.
file_get_contentsP
)fna.eQ
1
Reads contents of )fna.e into a
string.
fread()fhand%e,
)%en)
Read to +S1 or )%en 2ytes fro.
fi%e opened for reading. fopen
the fi%e #ith *2* in the .ode f%ag.
fruncateP)fhand%e,
)si7eQ
,runcates fi%e open for #riting.
4dds nu%% 2ytes if )si7e 0 fi%esi7e.
fFrite()fhand%e,
)str,-)%en.)
Yrites )str to fi%e opened for
#riting. 8tops at )%en if )str
%ength is greater.
file_put_contents(
)fna.e,)data,
-)f%ags.Q
Co.2ined fopen, fFrite 5
fclose. )fna.e can 2e a string or
an array. )fna.e is created or
o3er#ritten. *R the fo%%o#ing for
)f%ags
!alue 7eaning
19+;4PP+<R 4ppend to fi%e,
not o3er#rite.
SC];+C ock prior to
#rite
fseeA()fhand%e,
)offset,-)#hence.)
8ets fi%e pointer to )offset 2ytes
fro. )#hence #hich is one of
!alue 7eaning
8++];8+,
1
BS1
8++];C@R Current pos
8++];+<R +S1
1Refau%t
ftell()fhand%e) 1i%e pointer position
reFindP)fhand%eQ 1i%e pointer to BS1. @se%ess in a"
aI .odes
fflushP)fhand%eQ Co..its 2uffered #rites
1 )fna.e can 2e a @R.
7ath 8unctions
8unction /escription
abs()nu.) 42so%ute 3a%ue of )nu.
a#()arg)
1
9n3erse trig functions. )arg in
rad.
a#h()arg)
2
9n3erse hyper2o%ic functions
base_con:ert()nu.,
)fro.,)to)
Con3ert 2ases. )to 5 )fro. in
the range 2..AE. etters a..7
used for )fro.")to 0 10.
ceil()nu.) Rounds up )nu. to integer.
deche&()nu.) )nu. in he$adeci.a%
deg>rad()deg) Regrees to radians
e&p()nu.) e
)nu.
floor()nu.) )nu. rounded do#n to integer
fod()$,)y) 1%oating point re.ainder of )$"
)y
he&dec()str) Reci.a% eFui3a%ent of
he$adeci.a% )str. 9n3a%id
chars in )str are ignored.
log=H()nu.) TuessK
log()nu.,-)2ase.) )nu. to e or )2ase
pi()
4ppro$ 3a%ue for
poF()nu.,)2ase) )nu.
)2ase
rad>deg()rad) Radians to degrees
rand(-).in.,).a$) Rando. 3a%ue 0").in.. ).a$.
round()nu.,-)prec.) round(A.1&2) = ?
round(A.1&2,0) = ?
round(A.1&1JW,1) = ?I>
round(12811,62) = =>JHH
sqrt()nu.) 8Fuareroot of )nu. or <a<
1# is cos, sin or tan. 2cos, sin or tan. <ot on Yindo#s
*utput # 8oratting
8unction Note
echo )arg1-<'arg>.... +cho to standard output
print )arg Sutput a string
print_r()arg) )arg in hu.an reada2%e
for.at. Hand%es o2=ects too.
>ery usefu% #ith arrays.
printf()f.t,)arg1-,
)arg2...V)
1
Prints args using for.at
infor.ation in )f.t
8orat *utput
L2 9nteger as 2inary
Lc 48C99 char
Ld 9nteger
Le `%\ notation #ith
p Psee 2e%o#Q
digits
Lf 1%oating point
Ls 8tring
L$ He$adeci.a% %.c.
LC He$adeci.a% u.c.
LL itera% L
+ach L argu.ent can ha3e a nu.2er of optiona%
specifiers. 9n order they are
KL ! 8ign specifier. Sutputs I or 6. Refau%t is no I
sign
%0, % or %'c: padding specifier.
Uses 0, space or the character c for
padding
K3!a%ign.ent specifier. Causes %eft =ustification.
Refau%t is right =ustification.
KF!Yidth specifier. Sutput has a .ini.u. of
F characters.
KIp!Precision specifier. Reci.a% digits for f%oats and
nu.2er of characters for strings.
+3erything e%se in )f.t gets treated as %itera% te$t.
%&aples
8orat *utput
printfP*Ld*,2AQ 2A
printfP*L0Ad*,2AQ 02A
printfP*L.Af*,A.1&1JWEQ A.1&2
printfP*L.As*,*PHP 8cript*Q PHP
printfP*LsLAd*,*Route*,EEQ Route EE
1sprintf is si.i%ar 2ut returns a string
Strings
PHP strings are seFuences of sing%e 2yte characters.
,hey can 2e defined in four different #ays
Single Muoted! e.g. *+$p%ain,hat*. >aria2%es and
escape seFuences other than [* and [[ are not
e$panded.
/ouble Muoted! e.g. `Sne[n,#o\. >aria2%e
references and escape seFuences are e$panded.
$eredoc! ,o define co.p%e$ strings %ike dou2%e
Fuoted strings 2ut #ithout using dou2%e Fuotes. e.g.
)$ G '''PHP
'pre0
1or .ore infor.ation see
http!""###.php.net
'"pre0
PHP-
1.'''9R+<, .ust 2e fo%%o#ed 2y a ne#%ine character
2.,he actua% string contents fo%%o#
A.,he c%osing identifier .ust not 2e indented and
cannot ha3e any fo%%o#ing characters e$cept ;
NoFdoc! ,he sinF%e Fuoted string eFui3a%ent of
Heredoc. 8i.i%ar synta$ 2ut #ith '''*9R+<,* PFuotesKQ
8trings can 2e treated as 7ero 2ased arrays to access
indi3idua% characters, e.g. )<a.e-0..
String 7anipulation
8unction /escription
I Pnot IKQ 8tring Concatenation
strlen()str) 8tring %ength
strpos()str,)find,
U)offV)
strrpos()str,)find,
-)off.)
stripos # strripos
1irst )find in )str optiona%%y
starting at )off
Ritto 2ut reports %ast )find
Case insensiti3e 3ersions
strtoloFer 5
strtoupper
TuessK
chr()ascii) Char at )ascii
ord('strUinde$V) Srdina% 3a%ue
e&plode()de%i.,)str,
-)%i.. )
Returns array of su2strings of
)str de%i.ited 2y )de%i.,
optiona%%y #ith )%i. e%e.ents.
iplode()g%ue,
)pieces)
4%ias Noin
Concats )pieces array using
)g%ue.
ltri()str,-)c%ist.)
8i.i%ar%y rtri()str,
-)c%ist.)
and triI
8trip chars in )c%ist fro. %eft of
)str. 8trips spaces 2y defau%t.
strip_tagsP)str,
-)retain.Q
Riscard H,B 5 PHP tags.
Retain tags in )retain.
substrP)str,)start,
-)%en.Q
Returns su2string, optiona%%y
)%en %ong starting at )start. 63e
)start for su2string fro. end of
)str. 63e )%en to o.it chars
fro. end of su2string.
substr_countP)str,
)su2,-)start,)%en.Q
Sccurrences of )su2 in )str.
Sptiona%%y starting at )start
and #ithin )%en of )start.
str_replace()search,
)rep,)str,-)count.)
Rep%aces )search in )str #ith
)rep. Reports rep%ace.ents in
)count.
ucFords()str) 4%% #ords in )str to uppercase.
Conditional %&ecution
if (Condition,) ifStt;-elseif(Condition+) elseifStt;
.-else elseStt; .
Bu%ti%ine #Stt code .ust 2e p%aced in 2races, {}. ,he
; ter.inating each state.ent is o2%igatory ? e3en if the
ne$t character is a c%osing 2race, }.
A
PHP Quick Reference Card
1.02
sFitch ()3ar){
case >a%ue1!Code-
breaA-
-case >a%ue2!Code-
breaA-
....
-defaultOCode-.
}
)3ar can 2e a 2oo%ean, an integer or a string.
<ote the breaA after each case state.ent.
9f default is not the %ast option pro3ide a breaA.
,o e$ecute the sa.e actionPsQ for a range of cases
sFitch ()3ar){
case >a%ue1!
case >a%ue2!
case >a%ueA!Code-
breaA-
..._
case co.parisons are loose. Be#are of sFitch 2%ocks
that use .i$ed 3a%ues in indi3idua% case. ,he 2%ock .ay
ter.inate pre.ature%y 2ecause of a partia% case .atch.
(condition)PtrueCode!falseCode-
HCode can 2e a function ca%%. ,his is the PHP ternary
conditiona% operator. 9t can 2e assigned to return, print
or echo, passed as a para.eter in a function ca%% etc.
Parentheses are not necessary 2ut reco..ended.
%&ception $andling
'(php
function inverse()a)^
if ()$ GG 0) throF neF %&ception(*Dero di3ide*)-
return 1")a-
""not e$ecuted if e$ception is thro#n_
function whenExcept()eQ^
echo )e60get7essage().*'2r0*-_
set_e&ception_handler(*#hen+$cept*)-
""defau%t e$ception hand%er
tr"^
echo inverse(J)-
echo inverse(0)-""triggers e$ception_
catch (%&ception )e) ^
echo *+rror *.)e60get7essage().*'2r0*-_
echo *He%%o #or%dK*-
""e$ecuted since e$ception #as caught
throF neF %&ception(*Sops*)-
echo *BoienK*-""not e$ecuted
(0
)ooping
function whileLoopP)nu.Q^
Fhile P)nu. 6 0Q
^echoP)nu.Q.*'2r0*-
)nu.66-_
_
function doLoopP)nu.Q^
do^
echoP)nu.Q.*'2r0*-
)nu.66-
_Fhile P)nu. 6 0Q-
_
function forLoopP)nu.Q^
for P)iG0-)iQ'nu.-)iLLQ^
echo )i.*'2r0*-
_
_
breaA causes i..ediate ter.ination of the %oop. oop
state.ents after continue are skipped and the ne$t
e$ecution of the %oop is perfor.ed.
function foreachLoopAPQ^
foreachP)TSB48 as )key =6 )3a%ueQ^
echo )key.*G*.)3a%ue.*'2r0*-
_
_
function foreachLoopBPQ^
foreachP);8+R>+R as )3a%ueQ echo )3a%ue.*'2r0*-
_
foreach offers a neat #ay of iterating o3er an array.
1ser 8unctions
function calcArea()$,)y,)isRect G true)^
return P)isRectQ()$/)y!0.J/)$/)y-
""assu.e triang%e if )isRect is fa%se
_
8ca%ar function argu.ents can 2e gi3en a defau%t 3a%ue
? e.g. )isRect G true as a2o3e. Para.eters are passed
2y 3a%ue. ,o pass the. 2y reference precede the
para.eter na.e in the function dec%aration #ith an
a.persand, e.g. 5)y.
return causes i..ediate ter.ination of the PHP
function. 9f no 3a%ue is returned, or if return is .issing
the function return type is N1))
e&it()status) 6 die R causes i..ediate ter.ination of
the current script. 9f )status is a string it #i%% 2e printed. 9f
it is an integer it #i%% 2e the e$it status.
Superglobals
8uperg%o2a%s are arrays containing 3aria2%es fro. the
#e2 ser3er P#hen app%ica2%eQ, the en3iron.ent and user
input. ,hey are a%#ays 3isi2%e.
!ariable Contents
)TSB48 4%% 2e%o# in a one array
);8+R>+R 8er3er infor.ation
);T+, H,,P T+, 3aria2%es
);PS8, H,,P PS8, 3aria2%es
);19+8 H,,P fi%e up%oad 3aria2%es
);8+889S< 8ession 3aria2%es
);+<> +n3iron.ent 3aria2%es
);CSS]9+ H,,P cookies
,here can 2e .inor, ser3er6dependent, 3ariations in the
infor.ation returned in 3aria2%es such as )TSB48,
);8+R>+R etc. ,o check =ust #hat is a3ai%a2%e use the
script 2e%o# to du.p these 3aria2%es to your 2ro#ser.
'(php
function dumpThisP)sgQ^
foreachP)sg as )key =6 )3a%ueQ^
echo )key.*G*.)3a%ue.*'2r0*-
_
_
dumpThis('_S%R!%R)-
(0
7iscellanea
Darning ? thought%ess use of the features descri2ed
here cou%d serious%y da.age your ser3er insta%%ation.
,he prepend operator, S, can 2e used #ith constants,
3aria2%es, function ca%%s, e:al and include to suppress
error .essages.
,he 2ackticks operator Treturns the resu%ts of running a
she%% co..and. 1or instance, TlsT 6 dir on Yindo#s ?
#ou%d return a directory %isting. ,his can 2e assigned to
a 3aria2%e or echoed to standard output. ,yping WE #hi%e
ho%ding do#n the ,)0 key is a key2oard %ayout
independent #ay of entering the T operator.
e:al()e$pr) e3a%uates the PHP code pro3ided in the
string )e$pr. ,he string .ust 2e 3a%id PHP code ?
inc%usi3e of ter.inating se.ico%ons. +rrors in )e$pr .ay
cause the parser to die. Code in )e$pr for.s part of the
parent script so 3aria2%e assign.ents in )e$pr are
retained.
9$9 in $07)
,he safest #ay to e.2ed PHP code in H,B is to
de%i.it it using the '(php...(0 tag pair. Sther synta$
e$ist 2ut are not accepted 2y a%% #e2 ser3ers. ,he
resu%ting fi%e shou%d 2e sa3ed #ith the e$tension I9$9.
,o ca%% a PHP script 3ia 889 use
'K66#include 3irtua%Ga"path"scriptna.e.phpa660
9f the sa.e script is ca%%ed fro. inc%udes in different
H,B fi%es you can access the identity of the parent
H,B fi%e using );8+R>+RU*R+Q@+8,;@R9*V.
Notes
Color Be"
Fhile R PHP key#ord
funcName ? user function
echo ? %anguage construct
)3ar ? 3aria2%e *string*
A.1&2 ? nu.2er
true ? case insensiti3e
2&4 6 si.i%ar%y &
-option.
""co..ent
constant
@sing 3a%ue GG )3ar rather than )3ar GG 3a%ue. #hen
doing co.parisons against a 3a%ue a3oids 2ugs arising
fro. typing G in p%ace of GG.
&

You might also like