Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Maharashtra state board IT science Chap 5.pdf
1. Aafreen Shaikh(CSJC,Jalgaon)
Chapter 5 Server-Side Scripting (PHP) Textbook
Solutions
Fill in the blanks.
(1) PHP is __________ side scripting language.
Answer : Server
(2) PHP is _________ language i.e. there is no need for compilation.
Answer : interpreted
(3) A variable starts with __________ sign followed by variable name.
Answer : $
(4) An _________ is a variable, which can hold more than one value at a time.
Answer : array
(5) Information can be passed to functions through ___________.
Answer : arguments
State True/False
(1) PHP is platform dependent scripting language.
• True
• False
Answer : False
(2) $_POST is an array of variables passed via the URL parameters.
• True
• False
Answer : False
(3) A Function is a block of statements that can be used repeatedly in a program.
• True
• False
2. Aafreen Shaikh(CSJC,Jalgaon)
Answer : True
(4) PHP cannot be embedded along with HTML tags.
• True
• False
Answer : False
(5) GET should NEVER be used for sending sensitive information.
• True
• False
Answer : True
Multiple Choice Question (1 correct)
(1) The program file of PHP havev _________ extension.
• .asp
• .php
• .js
• .txt
Answer : .php
(2) A variable declared ___________ a function has global scope.
• outside
• anywhere
• inside
• none
Answer : outside
(3) The ____________ function returns a part of a string.
• trim()
• ucwords()
• substr()
• strpos()
Answer : substr()
Multiple Choice Question. (2 correct)
(1) The _________ and _________ are valid data types in PHP.
3. Aafreen Shaikh(CSJC,Jalgaon)
a) Double
b) Varchar
c) Integer
d) Array
e) Biglnt
Answer : Integer and Array
(2) Single line comment in PHP is possible using _______, __________.
a) //
b) /* */
c) #
d) <!-- -->
e) $
Answer : // and /* */.
Multiple Choice Question. (3 correct)
(1) ln PHP, three types of arrays are ________, _________, __________.
a) Indexed
b) Simple
c) Associative
d) Multidimensional
e) Complex
f) General
Answer : Indexed, Associative, Multidimensional.
(2) The scope of variable can be _______, _______, ______.
a) local
b) global
4. Aafreen Shaikh(CSJC,Jalgaon)
c) universal
d) static
e) final
f) outside
Answer : local, global, static.
Brief Questions.
(1) Explain any two features of PHP?
Answer :
PHP is the most popular and frequently used worldwide server-side scripting
language.
Following are features of PHP:
1. Simple: It is very simple and easy to use, as compared to other scripting
languages.
2. Interpreted: It is an interpreted language, i.e. there is no need for compilation.
3. Faster: It is faster than other scripting languages e.g. JSP and ASP.
4. Open Source: Open source means you need not pay for use of PHP. You can
freely download and use it.
5. Platform Independent: PHP code will be run on every platform, Linux, Unix,
Mac OS X, Windows.
(2) What are the rules for declaring variables in PHP?
Answer :
Following are the rules for declaring variables in PHP:
1. A variable starts with the $ sign, followed by the name of the variable
2. A variable name must start with a letter or the underscore character
3. A variable name cannot start with a number
4. A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and_)
5. Variable names are case-sensitive ($age and $AGE are two different
variables)
(3) What is server-side scripting?
Answer :
5. Aafreen Shaikh(CSJC,Jalgaon)
1. A server is a computer system that serves as a central control of data and
programs shared by clients.
2. The server-side environment that runs a scripting language is termed a web
server.
3. A user's request is fulfilled by running a script directly on the web server.
4. It is used to provide interactive websites.
5. Programming languages for server-side programming are PHP, Python, JSP.
(4) List the supported data types in PHP.
Answer :
1. String: A string is a sequence of characters. A string can be any text inside
quotes. You can use single or double-quotes.
2. Integer: An integer data type is a non-decimal number between -2,147,483,648
and 2,147,483,647.
3. Float (floating point numbers): A float (floating-point number) is a number
with a decimal point or a number in exponential form.
4. Boolean: A Boolean represents two possible states. TRUE or FALSE.
5. Array: An array stores multiple values in one single variable.
6. NULL: Null is a special data type which can have only one value NULL. A
variable of data type NULL is a variable that has no value assigned to it.
(5) Explain any two string manipulation function.
Answer :
Function Description
strlen() Returns the length of a string (i.e. total no. of characters)
str_word_count()Counts the number of words in a string
strrev() Reverses a string
strpos()
Searches for a specific text within a string and returns the
character position of the first match and if no match is found, then
it will return false
str_replace() Replaces some characters with some other characters in a string
Q7. Write Programs for the following.
(1) Write a PHP code which calculates square of any number using form.
Answer :
Coding:
<html>
<body>
<form method="post">
Enter a Number
<input type="text" name="sq"><br><br>
6. Aafreen Shaikh(CSJC,Jalgaon)
<input type="submit" name="submit" value="Sqaure">
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$sq= $_POST['sq'];
$s=$sq*$sq;
echo "<br><br> The Square of number is: ".$s;
}
?>
(2) Write Programs for the following.
Answer :
Coding:
<?php
$a="Hypertext Preprocessor";
echo "<br><br> String is ".$a;
echo" <br><br> Words in String is ".str_word_count($a);
?>
(3) Write Programs for the following.
Answer :
Coding:
Form.html
<html>
<body>
<form action="wc.php" method="post">
Enter Name
<input type="text" name="name"><br><br>
Enter Password
<input type="password" name="pass"><br><br>
<input type="submit" name= "submit" value="Submit">
</form>
</body>
</html>
wc.php
<html>
<body>
Welcome
<?php
echo $_POST["name"]; ?> <br><br>
Your Password is
<?php
echo $_POST["pass"];
?>