Professional Documents
Culture Documents
Server Side: Scripting
Server Side: Scripting
. e) 5-2 S
log)' (Sc1enc erver-Side Scripting (PHP)
f echno
~tiOfl
rrorfll
5 Server~Side Scripting
~
~
cise
Fill in: the blanks · j
. 1
. - - - - scri~hng anguage.
. AMffllfWJH)
pf{J' lS---
5.1 Introduction j
. :setv
er side · th · df
language 1.e: ere 1s no nee or compilation. t@ttftl!iMJE
toPHP
~nS• pf{l' iS - -
. .
!, , erpreted
Ans-: 1111 .able starts with _ _ _ sign followed by variable name. ~Mtti/ilf,Mii)
Avari
[Chapter at a Glance 5.3 Features of
PHP J.
is a variable, which can hold more than one value at a time.
PHP f eatures : - Simple, Fas_ter, Open Source, Platform Independen t,
Ans,:$
/. Afl----
Ans, : array . can be passed to functions through _ _ __
, !Jlforination
Case Sensitive, Error reporting, Interpreted etc. __ __
_s_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Ans,,• argument
.
i,
5.4 First Sample
code of 11
_______,,
c=:= State True/False I
tJP ·s platform depende nt scripting language.
JI J. Prii 1 .
Jl !)_ ..Q AflS, : False ·
[jij@ftiilfMJ)j
PHP file extension. PHI' Case Sensitivity, J}_ $ POST is an array of variables passed via the URL parameters.
php, how to execute PHP Data Types: - 2. -
PHP variables, rules Control structures in PHp:.
PHP program, Sbing, Integer, Float, Ans,: False
for declaring If statement, if else statement.
J. AFunction is a block of statements that can be used repeatedly in a program.
how to save code Boolean, Array,
variables, different ·Loop structure in PHP, .
in specific folder NULL Comments in
variable scopes For, foreach With syntaxand
PHP, Single line and Ans.: True
in PHPwith examples
multi-line commen!-5,
examples 4, PHP cannot be embedded along with HTML tags.
Ans. : False
( "'""'\
5.5 PHP String s. GET should NEVER be used for sending sensitive information. rMt!ffiliN:M
Functions 5.6 PHP
Ans.: True
Arrays
strlen(), strrev(), substr(), strtolower(), [ · Multiple Choice Question (1 correct)
trim(), ucwords(), str_replace(), Create an array, types of array, indexed
str~word_count(), strops(), substr_count() array, multi-dimensional arrays, PHP associative I. The program file of PHP have _ _ __ extension. @MffilfMIJl
arrays with syntax and examples. (a) .asp (b) .php
(c) .js (d) .txt
Ans.: (b)
2,
Avariable declared _ _ _ a function has global scope.
(a) outside · (b) anywhere
Simple HTML form wi th php code, GET vs POST (c), inside
With examples, create database connection object,
(d) none
SQL statement and its execution, cookies and
Ans.: (a)
sessions in PHP.
• e) 5-5
. n Technology (S c1en c Server-Sid S
5.6
TPS Jnformatro . e Ctipl:i
t tem ents in PHP code, which are not visible . "g (~lfy
12. . .. .... are the s a In the ou.1:pU.t )
ecia l variable which can hold
program . Of th~ ... js a s P more than on
t k . . " fl . . • . • e value at a fun
C 0 llllllents ~ ~
Ans. : ent allows programmer o ma e decision bas ed on .
13. The. . . . .. .. . .statem one or i9·, .. artaY t res :multiple values in. single variable.
so
conditions. 1\\0 ~
1 ;,11,· Afl ·····. •· D
l'li1"-IMII--
W&IIW¼
Ans. : if ent allows programmer to make decision based 30· . aJ.'l'aY p=P {unction is used to create an arr .
14. The·· ·····:·.statem
on I ther this
e·
..,,. · •. • • r-,. ay variable
that condition. or ,., flle .. •· .
Ans. : if else 3t• : artaYO . ..types of arrays in PHP.
15. . ... . .. . . are u sed. t~ execute the same block of code repeatedly as lon µi•· fllere are . . . . . . .
condition is satisfied. g as cert .
a1n 3Z, e
Ans.: loop ,. : -rttre .. .arrays are the arrays with numeric index.
16. . .. ... _. loop w orks only on arrays. t,JI r1:te · ·•·· · l%1iWD
Ans. : foreach ~ 33, Jlldex:ed .
l 7. . .. .. ... functions returns the length of a stnn g. t,JI•· : .arrays are the arrays with named keys.
em;~
_,_
.
'[he · · · · · · · · MUffilfMiJl
Ans. : strlenO 34· odative
. .. ... . . functions counts the number-of words in a string. h ..
18.
, ASS
J\11•· • .arrays are t e arrays contauung one or more arrays . ""
Ans. : str_word_countO '[he . . • •· · · · · 1Wffli!:!•?n1
19. . .. .. .. . function reverses a string. 35. . rvtulti-dimensiona l .
5
Ans. : strrev() J\!1 • •'[he . .... ... Junction is used to return the length of an array.
20. . ...... . function searches for a specific text within a string. 36. ·
Ans. : strposO
21. . .. .. .. . function replaces some characters with some oth er ch aracters in a string.
Ans. : str_replace()
cJ\11•• : countO
· 5.7 PHP User Defined Functions j
22. . .. ... . . function returns a part of a string. [M ffit1011,;1a A is a block of statements that can be used repeatedly in a progra"" . _.._,""'
m,,.
tl&!ffll~ 1►f)!
Ans. : substrO 37· · · •.. · • ·
23. . .. .. .. . function converts a string to lowercase. tf~fflfili1•►JD Ans, : function
Ans. : strtolower()
· 38. Information can be passed to functions through ........ .
24. . ... .... function counts the number of times a substring occurs in a string.
Ans. : substr_count() Ans. : Arguments
25. . ----
. ...... . .converts the first character of each word in a string to upperca,.s.e,. 39. . .... ... .are ·specified after the function name, inside the parentheses.
. AMM411MJD
Ans. : ucwords() i\fls. : Arguments
26. . .. ... .functions removes whitespace and other predefined ch aracters from both sides 4o. The -... . .. . statement is used to let a function return a value.
r1@t1f!llfNJB)
of a string. Ans. : return
J
.,.•
Ans. : trim()
J [ 5.8
PHP Fonn Handling
5.5 PHP Strin g Functi ons
41.
27. A .... . ... is series of ch aracters. ~MMUtWJII Ans. :The
HTTPformd . sent with the ········.rnethod.
PO ata is
Ans. : string
42. . ST
28. A .. .. .. . . i s a block of statements that can be used repeatedly in a program. 1.Jll -•.•.•. .is an anay of va<iables passed,;, the URL p•"'"-
AnS; , ..$_GET
A ns.: f unction
. . ;
~,f.'l'ToljJ{
Server-Side .
5-7 Techn ology (Science)
TPS Informa ti on Technology (Science) Scnpt'1 tiOJl
or!l1a .8
~ ng (P~P) ~/ .
the HTTP post method.
_ ....... . js an array of variables passed via 11" er-side scripting is more · J.
43 I serV Seel.Ire th
. . . ~~-,,.5
Ans. : $_pOST .... ... . meth od 1s visible to ev eryone. j. • rrue
anClient-s·
from
t'on sent . a form with Id eSc~ Ptin 'd i Sc,,Ph
~~5• . BP is easy to learn and runs f . .
44. Infonna 1 e fic1ent1y g. ng ll'HP1
f ~
Ans. : GET itive data . ~ . on thec1·
. meth od may be used for sending non sens ,. . false ~
45_ ....... . 1 A~5• •friP is an interpreted language.
'ent•side.
Ans. : GET
meth od is invis ible toe . ~1
Infor mation sent from a form with ... ..... veryone. 6, .rrue
46. A~5' · ;117 runs on only on WindowS. ~
f~
Ans. : POST
of informati on to send . 1· .false ~
47. ..... ...method has no limits on the amount 5 --
~ · •pBP runs only on windows
--
Ans. : POST server.
1
>
Ans. : Sessi on 14.
Ans. : True
I True or False 15. You need to pay for use of PHP.
Ans.: False
Ans. : False
61. Arra y inde x alwa ys start s with zero .
Ans. : True
array.
62. Thel en() function is used to retur n the leng th of an
Ans. : false
nsional arrays . .
63. PHP can hand le mult iple levels of mult i dime
Ans. : True
64. We can create our own functions in PHP .
Ans. : True
Ans. : True
a function.
69. Retu rn statemen t is used to retur n a valu e of
Ans. : True
TP S Inf orm a tio n Te
d m o log y (S cie nc e) 5-1 2
Se rver-S ide Sc rip tin g
[ 5. 8 PH P Fo rm H an dl in g
(PH P)
~ ~; -Introduction to PHP~~
[__ •dely used open :Ource server s:e. ;roo-ra
o
nun·-
mg langua
·
.......... is a w1 ge ivh·
1. ... various platforms. Ich
runs on .
(a) Word (b) PHP (c) Excel (d) PowerPoint
Ans.: (b)
5.2 Server _Side Scripting
Ans. : (a)
3.
The server side environment that runs a scripting language is termed ...... .
(a) Browser (b) Computer (c) Web server (d) Client
Ans.: (c)
·5.3 Features of PHP J
L-----------
[
4. ..........is a script executed on server which generate dynamic HTML pages.
(a) PHP (b) MS Word (c) MSExcel (d) Client
Ans. : (a)
5. . The PHP code can also be embedded with HTML tags using ..........
(a) <!Php! > (b) <?php and?>
(c) <=php > . (d) <#php#>
Ans.: (b)
6. PHP files are sav:ed with .......... extension. -
(a) .html (b) .xml (c) .js (d) .php
Ans.: (d)
7. ········.keyword is used to display text on web page.
(a) echo (b) print · (c) write (d) cin
Ans. : (a)
8 .. ·· ... .is a symbol or name that stands for a value.
·
(a) Method (b) condition (c) Variable (d) Value
Ans. : (c)
~ .
TPS Tnformc1tio n Tech nolo gy .
(Scie n ce·) 5-14 Serv er-S ide Scri pti (PH P)
ng
9. A vari able in PH P star ts wit h th
e ··· ·· ···.sign foll owe d by nam e of the
vari able .
(a) # (b) @ (c) = (d) $ ~f i$ Wffl1
A~ =~ 1
.
1
o. PH P var iabl e nan ,e cam ,ot star ts wit h a · ·· ·· · ·· •
(a) Nu mb e r
_(b) Cha racte r
(c) Alp han um eric
(d) Dol lar
;\JlS , ; (a) . . . : .
Cor rect met hod for dec lari ng PH P
11. var iab le 1s . .. .•... .
(a) # age (b) $ age (c) @ age (d) age Mffl&JJJ
j\JlS ·: (b) . .
_ _ A var iabl e dec lara tion .. ._.~ ·-· .a fun -4
12
(a) insi de (b) mid dle
ctio n has a_ GL OB AL SCOPE. ttiM®iQWJJ
(c) out side (d) top side
j\JlS, ; (c) . . .
_ A var iabl e dec lare d ... ..... .a fun ctio
13 n has a _LO CA L SCO PE
(a) Ins ide (b) out sid e (c) bet wee n (d) wit hin
J\JlS,: (d)
14_ pHP stor es all .. .. ., ...var iab les in an arra y call ed $ GL OB AL [Ind ex]
(a) loca l (b) glo bal
tf ff f~
(c) Sta tic (d) wit hin
Ans. : (b)
1s. To check dat a typ e of var iab le in PH P ..... ... me tho d is use d.
(a) var _du mp () (b) var _de l()
(c) var _re mo ve( ) (d). var _de lete ()
Ans, : (a)
16. ....... .. are the sta tem ent s in PH P cod
e wh ich are not visi ble in the out put
pro gra m. of the
(a) Me tho ds (b) com me nts ·(c) Obj ects (d) val ues
Ans.: (b)
17. How to add a sin gle line com me nt in
PH P?
(a) II (b) * 1r (c) $ (d) @
Ans.: (a)
18, How to a mu ltil ine com me nt in.PH
P ?
(a) II (b) # .(c) $ (d) I* and * I
Ans.: (d)
19,
········· stat em ent allo ws pro gra mm er to ma ke decisio
n, bas ed on one or more
conditions.
(a) if ~
(b) loo p .. (c) variable (d) me tho d
Ans.: (a)
~ s ·ence)
. n Techn ology ( c1
-rnc1 nfor111vtion ~
5-15
----------
Server-s·d
- " esCriPti~
.
mmer to make decisions based on . either th·
&(1>11
1I fl"
1nforfl'la
.
ttOil
Techno logy (Science)
sub tr·
16
Server-Side Scripting (PHP)
nt. "
-]J
a nouwr<s pro
n gg1ra s tng occurs in a strin
~ . ~ s Ot I~ ...... . . subs tr_count() g.
{b)
·······stateme ' . t i1 3o. (a) substr0
20. decision. (b) if else (d) strlen()
(a) loop (d) method
tri1n0 lfflbliWJll
(c) .
(c) variable character of each word .
All'' (I,) _function converts the first m a strmg to upper case ·
as
t the same block of code repea tedly 1ong as a ..... ... (b) strtolower ()
Ans.: (b)
.are used to execu e ~~ 31. (a) subs tr().
2l. ·····di tion is satisfied. ·
{d) loops ~ (d) ucwords() tmf&!MiU
(b) Method (c) Object (c) trirnO
con
(a) Variable ·
· hlt other predefin d h
-~
,>\/Is" function removes w espace and e c aracters from both sides
Ans.: (d)
········ loop works only on arrays.
3Z, ..... ...st . IMIIWII
.
(b) for (c) foreach (d) forone of a nng. (c) straps() (d) strrev()
22. (a) for next (a) trun 0 (b) strlen()
Ans. : (c)
23.
(a) ····strrev
Ans. : (b)
() (b) strlen
· h f t· g
function returns the lengt o a s rm
() (c)
.
strlength()
d .
s ma strm g.
.
{d) substr() ~ c
f./lS•: (a)
l
1
\Jrnrr1•r,u
J
24. ..... function counts the number of wor (a) String (b) Number {c) Object
(b) str_ word_count()
(a) strlen() Ans.: (a)
a program.
(d) trim() ments that can be used repeatedly in
(c) substr() 34. A ···:···· is a block of state
(c) method (d) varia ble
Ans. : (b) (a) function (b) class
111 ! ~
1il !'~ffl1t~~+ll!'i~
25. ........ func tion reverses a string. lb&liMq ~A~,"Hff•.
(a) strrev() (b) trim() (c) UCwords() (d) strop s{) Ans.: (a)
Ans.: (a)
ific text with in a string.
98 [ 5.6 PHP Arrays
26. . ....... func tion searc hes for a spec
{d) str_replace() more than one value at a time. tbitffii1•h\tJI
(a) substr() (b) strrev() (c) strp os() 35. . ...... . is a variable whlch can hold
(c) Object (d) Constant
Ans.: (c) (a) Array (b) Method
in a string.
. .. ..... function replaces some char
acters with same othe r character Ans.: (a)
27.
(a) strrev() {b) str _rep lace() In PHP .. ...... function is used to
create array.
36.
(c) trim() (d) strpos() {b) array() (c) value() (d) variable()
(a) arr()
Ans.: (b) Ans.: (b)
........ ftmction returns a part of a strin
g.
!MtffllfMD ........• ti&tiffitf11hHl .
28. 37. Syntax of creating array variable is
(a) substr() {b) trim() (c) strrev() (d) str_len() (b) #a= arr()
(a) @a= array()
Ans.: (a) (d) $a= array (values)
(c) = array()
29.
·······•iunction conv erts a string to lowercase . !MrffilfWII Ans.: (d)
tlti !ffihfJ❖JJl
rd (b) strtolower() 38. PHP.
(a) UC wo s() There are ..... ... .types of arrays in (d) Four
(c) strlow er() (d) trim() (c) Three
(a) Two (b) One
Ans. : (b)
Ans.: (c)
chnology (Science) 5.18
·
-1_7 _ _ _ _ _ _ _
___s_ se_rver-Sictes . 3 ·on Te - - -- - -- --..:_ _ Server-Side Scriptin g (PHP)
criptin 0 .
Technology (Science) - 1~1 r)11 tl
.
ation sent from a form with ........ method is ..
~
'th a numeric index. -rr5 v1s1ble to everyone.
-rrs 1nforn1atwn 1r1forJll ,,., . (b) GET (
tl1e arrays w1 c) HDp (D)
.arrays are ' (b) Indexed s pOSi Ffp !II
,~lf,m Jll'"'~••to.=~
. IF~
39, 4' (a)
(a) Associa tive . (d) Normal . 'bl
: (bl rna twn . sent from a form with .. ...... meth od 1.s m ·
ulti-din1ens10n al i\ns• ( v1s1 e to everyc i',2.
(c) M [nfor (b) GET (d) ,.,.,,,.,
49, (a) pOST c) HDP ru-
Ans. : (b) the arrays with named keys. .
_ .. .arrays are (b) Associative
40
AIIS·: (a)···· · ,NEVER be used for sending sensitiv
e information.
(a) Indexed (d) Normal
(b) HTTP (c) GET (d) FTP 1Htitfi•lfl4l
(c) Dinlensional 50. ... pOST
(a)
Ans. : (bl taining one or more arrays . · HP. d 1
ays are arrays con . Af\S•
: (cl
.method m p IS use to check whether variable has va ue or not.
(b) Indexe d .. .. ..
41. .. .. .arr
(a) Multi-dinlensional 51. i~) outset() (b) inset() (c) noset() (d) isset() (fflfffilfWfAj
(d) Numb ered
(c) Associative 11 fil th h
"
•115•: (d)
A ....... . is a sma text e at t e server sends on the user's computer.
Ans. : (a) ·1
. dex a[ways starts wit 1 ...... ·· · 52 (b) session
Array m · (a) · Cookie
42 four
·
(a) one
(b) two (c) zero (d)
(c) Presentation (d) Me th od (1Mt/ilfWf1j
Ans.: (c)
:J J\f\S,: (a)
.. .are sent along when browser requests server pages. {l~fflUf1 1fJU
-
L[_ _ _ _ _ _.::.5::.: _P
.7__:P~H _ ef_i_n_ed_ F_u_n_ct_io_n_s__ __ _
_ U_s_er_D 53,
(c) Method (d) Server
(a) Cookie (b) Session
in a program.
43. A ....... .is a block of statements that can be repeatedly Ans.: (a)
s.
(a) function (b) condition (c) object (d) value
54, is used to store information on server to track user activitie
(b) session (c) Presentation (d) Object
Ans. : (a) (a) Cookie
44. Information can be passed to functions throug h ... .....
. ltff iq Ans.: (b)
ation on all the pages.
(a) Condition (b) arguments (c) array
(d) . variable
55. ........ helps w eb application to maintain user inform
(a) Session (b) presen tation
Ans.: (b)
. t
(d) obiec fl&ftf#lt1 1fftj
····-
(c) Cookie
5.8· PHP Form Handling J Ans.: (a)
45. The form data is sent with the ........ metho d.
(a) HTTP POST (b) FTP POST \ MCQ (Two Correct Answers)> -
(c) STP POST (d) SMPT POST
[ 5.1 Introduction to PHP
Ans. : (a)
-------==::
5-21
ology (Science)
d
e1n
I
5.2 Server Side Scriptinge
User DefinE!d Fun ctio ns
5_7 PHP p
~
--m ing languages for server side rograllUni.ng
rau ,,, - :e
(b) Windows (c) Linux
. me can start with a .···-·-· .or .tt·-· -·-·. progpBP
( ) Le er . ( )
Afuncl:lon Ina {d) Underscore I (f) Java and JSP
-
c
-
(b) Number .
--
(a)
~~--
21.
~~
l]I11X
-==
(a) symb o (e )
22
Form data can be su
· (a) Return
PHP Form Handling
24. .. ... .. ..
is an array of varia bles passedthvia URL
variables passed via HTTP POST me od.
(a) $GET (b) $_GET (c) $_POST
parameters and .. .. .... ·1·s an arra
{d) . $POST
~ c:
AoS, • ;-;::t:=
'-- -- -; 5.4 :-- :-~
Firs Sample code of
~
(iiil a anguage e.g. JSP and n.
•.,) open Source : Open source means you need ASP.
mFHP ~ re, types of ,rrays ~;: :Hp ~:,,ays · , ------.........__ (1' download and use.
·
not pay for use of PHP y
· ou can freely
12.
(a) inside (b) multiple t
Platform Independent : PHP code will be run
(v) OS X, Windows. on every platform, Linux, Unix, Mac
(d) associate
(c) indexed
(e) outside
(f) multi-dimensional c------:--:--~s:.4~;F1:.r:st~s:am=p~le:--c~o:de-o-:f:-:-P-H_P_ _ _ _ _ _ _ J
Ans. : (c), (d), (f)
(i) Type the PHP code using any text editor (Notepad).
I 5.1 Introduction to PHP J (ii) Save with .php extension in appropriate folder.
.
L -- - - - - - - - - - -
2. Explain Server Side Scripting? (ii) A variable name must start with a Jetter or the underscore character
Ans.: (iii) A variable name cannot start with a number
(iv) A . · · h racters and underscores
(i) A server is a computer system that serves as a central control of data and programs variable name can only contain alpha-numenc c a
shared by clients. (A-z, 0-9, and_) .
(v) y • . .. d $AGE are two different variables)
(ii) Tl,e server side environment that runs a scripting language is termed as web server. anable names are case-sensitive ($age an
) 5-25
- T,ei~ch~n~o:_<:lo~gy'.-.(:S::'.
'. ci::en_:::c~
e - - - - - - - - - - - -~ . Technology (Science)
TPS 1nfonnat1on T. f11ati 0 n · 5-26
Jnfor
. . ble scopes in PHP. tf5 •n the operators used in PHp
7. Explain vana J:~J'1al ,
o ators used in PHP are .
Ans, : d"fferent variables scopes in PHP : l. . orer .
There are three 1 . ~~s- · . '-Jlletic Operators
t,nh•
local Operator
global +
static
. ble declared outside a function has a GLOBAL SCOPE
(i) A vana _ . and ·*
accessed ou ts1de a function. . . can only b
~
•able declared within a funchon has a LOCAL SCOPE
. · . . ~c
e I
(ii) A
accessed within that funct10n. an Only b %
e want a local variable not to be deleted then 'we have to use . f . e
(iii) If w o static k Relational Operators
eyboa d
8. Explain PHP data types. ~ Operator Definition
Ans.: ___>_·-...,--t----G er~t:'._'h"'an _ _ _ t---...'Ex
.) String: _ A string is a sequence of characters. A string can be an t . .:.:r:..:e:.:
at:: .:~am5p~le'.__
(1 · Y ext ms·a ___ _ _ __:_a::::>::b__ ·
You can use single or double quotes: · 1
e quoies. ___<_ _ _+ _____:L=e:::s::_ s t'.'. 'hLQ,ann 7
(ii) Integer:- An integer data type is a non-decimal number between _2 147 >= Greater than or eq~u:a:i""1:: to-:----t---.:.a~<:.b'.:'._ _
4
2,147,483,647. ' , s3,648 and <= less than or equal to
a>=b
float (floating point numbers) a<=b
(iii) . :- A float. (floating point number) 1s
· a numb . Equal to
decimal point or a number m exponenhal form. er W1Iha a=b
;,- Explain PHP If statement with syntax.
(iv) Boolean : A Boolean represents two possible states: TRUE or FALSE.
~ns. :
(v) Array:- An array stores multiple values in one single variable.
if statement - executes some code if one condition is true.
(vi) NULL:- Null is a special data type which can have only one val . NUl.
variable of data type NULL is a variable that has no value assigned to ~e. L. A Syntax of if statement is
coding:
<?php
$a:::100;
$b:::200;
if($a>$b)
echo "$a is greater than $b";
else
echo "$bis greater than $a";
2. PHP Program to print sum of two numbers.
Coding:
Output:~
<?php 9 localhost/phpigreat.php X +
$a=10; f- -"' C (1) localhost/php/great.php * • e
$b=20;
200 is greater than 100
$c=$a+$b;
echo "<br><br> Sum of two numbers is $c";
?>
11111 logY(Science
. chnology (Science) 5-33 f echflO •·~·- - -) - - - 5-:¾
f 1113 uon Te
S f1l'atiOll
. -------
",::bo <:br> Extract
erver-Sid e Seri . ..ii\rfo - Setver-Side Sc. .
TPS ln or . t numbers from 1 to 10
using for loop. Pting (I' chO some part of Str· "
.... to pnn
pHPprograu, tli>)
11·_
nptin g (PHP)
4. e ",::b r:>,::br> Converts String mg .substr($
echO in low a,5,3);
C
",::br><:br> ap1.ta lize each wor ercase ".strtolower($ )
ech 0 d of s . " a;
_______
_ trmg .ucwords($a);
?'?
\
echo "<br> $i";
e:i \ocalhost/ php/string,?hP X +
k ➔ .C (i) \ocalhost/php/string.phr,
Output:· * - e :
I C) \@l I lZ_J . is
G) localhost/php/for.php X + Strl111! information technology
~·
t' C Length of String is 22
7 (D localhost/php /for.php
* ~ e Words in String is 2 .
1
2 Revers~ of String is ygolonhc
et noitamrofni
3
4 Position of o in String is 3 ·
5
6 Replace Infonntaion with Info
rm information technology
7
8 Extract some part of String mat
9
10 Converts String in lowercase
information technology
C~i taliz e ~ach word of strin
g Information Technology
if ( ("Volvo",22,18),
Output : • Kul"
array ("Biv, 15 13),
'1[,>1 f vv , ,
5
array "Saa , ,2) ,
b"
Y(
arra "Land Rover",1715) ,
C olor ruu11 '" " ~u c- array (
R cd
Blu e
810 \\ rl
); 0 $ca rs[O][O) .": In stock: ".$cars[O]ll].", sold: . Sc
.
Pulk
P ur p lC'
ech ][OJ "· In t k- .. $c · ars[0]l2] . .<br>"·
echo $cars[1 ... · s oc . .: ars[l ]ll ].", sold:".$cars[]112].".<br>":
$cars[2][0). : In stock: .$cars[2l[ 1].'' sold·" c, l . '
echo ., .. ' · -->1.ars 2]12].. <br>"·
echo $cars[3 ][0]. : In stock: .$cars[3](1].", sold:".Scars[3]12].".<br>";
8
stock.
· PHP program to print the infonna tion about cars sold and c~rs in
Coding :
~ Phf~ -
[
--- --
$car~ = arr,w
- - - - - - - - -- - -
w lltiO!l 'fecru1u•~o, • J - jts
. chnoJogY (Science)
5-37 S iii rl1' .
erver-Side Seri . ,rl" l o "' "10+20=" .sum.(10,20 ). "<br><br>"·
nforrnat1on Te .
rrs I . t Name and Price of the product by passi Pting (Jlt, ec"o
"~) '
pl{P program to pnn . ng argUtne1:11s t "l l +2= " .sum(ll,2). "<br><br>"·
echo ,
. 10. £unction-
o "' .. 1+9=" .sum(31,9). "<br><br>"·
eo• 0 3 · ,
G] loca!hosVphp/ svm!un.php
X +
~ ➔ C ©
I "P duct name is $n and Prite is $price <br><br>"; . localhost/php/ sumfun.php
~~ ro . Jo+20= 30
~1 e
l 11-2= 13
pr("Notebook" ,45); 3 1+9=40
pr("Calculator",400);
pr("Pen" ,30);
?>
l-'=..!..@_J__g _,
Output:
(;- ➔ Q (D localhost/pnp/ funct ion3rg;.ph~ * 4' ~J e :
Product name is Notebook and Pncc ts 45
~
</ form>
- ~etu
- rn- $c-; - - - - - - -- - - -
</body>
-hn ology (Science) 5
5-39 Te'-'~-~
(ll' ~tJ·ori · -=--=-~~-:_-:=_-:=_-:=_-:=_-:=_-:=_-:=_-:=_-:=_-:=_-:=_-:=_-:=_-.:. _ -40
0
,.;;1
,r'
ri ,roe==
"text "·name ="name " id ="i"d n
- ame"> b
i.!1Put 11 , . </labe l> < r><br>
t. c ender
7
t. l3 bel d
- "r a 10 n" " ame "
= g en er id=" ·dd "
. ut t)'Pe- . " " " l ....gender" value=" "
t.illP . -"r adio name= gender id- "id male >Male<br><b
<:?php . ut t)'Pe- . " " - ....gender" value="f " r>
t.illP - "radio name= gender" id-"id emale >FeMale<b > b .
$tl o=c$_GET["tl "]; . ut t)'Pe- . " " . - ....gender" value=" " r < r>
t.illP e=="subrrut name= submit" value="sub . ,, . ,, other >Other<br><br>
$tZo=c$_GET["t2"]; t.il'Put typ . nut id= submit">
$c=$t1 +$t2; . ,, ,:_/form::>
,, b <br> Sum of two numbers 1s $c ;
echo < r> t.fbodY;;,
?> ,:_/ html::>
Output : d phP " . _ ·
<:-- ➔ C <D 1oc.;:ilhost / f)r,p;mrm ntm! * <!o ,,,, e •
$servern
arne= pgsql.host-localhost;dbname=coll "·
" . ege ,
Entel Fust !'\umbC':%" 1.2 5
3
me="postgres ; ·
$userl1
Em~ ~coud :Sumbcr r,o
sword="laxmi" ;
$pas
1 Add
$COIU1"'new _PDO($servemame,$usemame,$password);
if(isset($]OST(' submit']))
I
$narne=$_POST(''name''];
$gender=$_POST("gender"]; .
$sqlo=c"INSERT INTO student(name,gender) VALUES ('".$name."','" .$gender."')";
$conn->exec($sql);
13. PHP program to create admission form for student. Accept name and gender from echo "N ew record added successfully";
the student. Create a college database and create table student having the fields
name and gender. ·
Steps lo create database and Table :
1) For database creation ➔ open postgres sql terminal - ➔ create database college; and \ PHP Extra Programs for Practice~ ·
p ress enter.
Write a PHP code which calculates and prints addition, subtraction,
2) For Table creation - ➔ create table student(name text, gender Booleatn); press enter ,
table w ill be created . multiplication, division of tw·o numbers using form.
i\ns. :
Now type code in admission.php
Coding:-
. <!DOCTYPE html>
<html> <html>
<body> <bod y>