Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Students can Download Chapter 10 Server Side Scripting Using PHP Questions and Answers, Plus Two Computer Science Chapter Wise Questions and Answers helps you to revise the complete Kerala State Syllabus and score more marks in your examinations

Kerala Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Plus Two Computer Science Server Side Scripting Using PHP One Mark Questions and Answers

Question 1.
PHP files have a default file extension of ______.
(a) .html
(b) .xml
(c) .php
(d) .ph
Answer:
(c) .php

Question 2.
A PHP script should start with.
(a) <php>
(b) <?php?>
(c) <?php>
(d) <?php?>
Answer:
(c) <?php>

Question 3.
We can use_ to provide multi line comments.
(a) /?
(b) //
(c) #
(d) /* */
Answer:
(d) /* */

Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Question 4.
Which of the following php statement/statements will store 111 in variable num?
i) int$num = 111;
ii) intnum = 111;
iii) $num = 111;
iv) 111 = $num;
(a) Both i) and ii)
(b) All of the mentioned.
(c) Only iii)
(d) Only i)
Answer:
(c) Only iii)

Question 5.
What will be the output of the following PHP code?
<?php
$num = 1;
$num1 = 2;.
print $num . “+”. $num1;
?>
(a) 3
(b) 1 + 2
(c) 1. + .2
(d) Error
Answer:
(b) 1 + 2

Question 6.
Which of the following PHP statements will output Hello World on the screen?
i) echo (“Hello World”);
ii) print (“Hello World”);
iii) cout(“Hello World”);
iv) sprintf (“Hello World”);
(a) i) and ii)
(b) i), ii) and iii)
(c) All of the mentioned.
(d) i), ii) and iv)
Answer:
(a) i) and ii)

Question 7.
What will be the output of the following PHP code?
<?php
$total=25;
$more=10;
$total=$total + $more; .
echo “$total”;
?>
(a) Error
(b) 35 students
(c) 35
(d) 25 students
Answer:
(c) 35

Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Question 8.
Which statement will output $x on the screen?
(a) echo “\$x”;
(b) echo “$$x”;
(c) echo“/$x”;
(d) echo“$x;”;
Answer:
(a) echo “\$x”;

Question 9.
What will be the output of the following PHP code?
<?php
$a = “clue”;
$a = “get”;
echo “$a”;
?>
(a) get
(b) true
(c) false
(d) clueget
Answer:
(d) clueget

Question 10.
PHP’s numerically indexed array begin with position ______.
(a) 1
(b) 2
(c) 0
(d) -1
Answer:
(c) 0

Question 11.
What will be the output of the following PHP code?
<?php
echo $x— != ++$x;
?>
(a) 1
(b) 0
(c) error
(d) no output
Answer:
(d) no output

Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Question 12.
List Superglobals used in PHP.
Answer:
superglobals used in PHP is given below.
$_REQUEST, S_POST, S_GET, and S_COOKIE.

Plus Two Computer Science Server Side Scripting Using PHP Two Mark Questions and Answers

Question 1.
Name the PHP functions we use

  1. to find the length of a string
  2. for comparing two strings

Answer:

  1. strlen()
  2. strcmp()

Question 2.
What is the main difference between JavaScript and PHP?
Answer:
JavaScript is a client side scripting language whereas PHP is a server side scripting language.

Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Question 3.
What will be the output of the following PHP code?
<?php
$a = 10;
echo ++$a;
echo $a++;
echo $a;
echo ++$a;
?>
(a) 11111213
(b) 11121213
(c) 11111212
(d) 11111112
Answer:
(a) 11111213
It works as follows
<?php
$a = 10;
echo ++$a; → Here pre increment first add 1 to
10 then it prints 11
echo $a++; → Here it prints 11 and then add 1 to
11 and stores in the variable $a, i.e. $a=12. echo$a; → Here it prints 12.
echo ++$a; → Here pre increment first add 1 to
12 then it prints 13 ?>

Question 4.
What will be the output of the following PHP code?
<?php
$x=”test”;
$y=”this”;
$z=”also”;
$x.=$y.=$z; echo $x; echo $y;
?>
(a) testthisthisalso
(b) testthis
(c) testthisalsothisalso
(d) error at line 4
Answer:
(c) testthisalsothisalso

Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Question 5.
What will be the output of the following PHP code?
<?php
$y = 2;
if ($y— == ++$y)
{
echo $y;
}
?>
(a) 2
(b) 1
(c) 3
(d) no output
Answer:
(a) 2
It works as follows $y=2;
Here $y – – (LHS of the condition) , it first use the value of $y i.e. 2 hence LHS becomes 2, then its values decremented by 1 so $y now becomes 1. ++$y(RHS of the condition) first it changes the value
i. e. incremented by 1 now $y=2 hence RHS becomes 2
Here LHS and RHS are same then the condition $y— == ++$y returns true.
So it prints the value of $y, i.e. 2.

Plus Two Computer Science Server Side Scripting Using PHP Three Mark Questions and Answers

Question 1.
A special type of array which is not supported by C++ is used in PHP. Can you describe the features of that array with example?
Answer:
Associative arrays
Arrays with named keys and string indices are called associative arrays.
Syntax: $varibale_name=array(key1 =>value1, key2=>value2,etc);
Eg:
<!DOCTYPE HTML>
<html lang=”en”>
<head>
<title>
We are learning PHP </title>
</head>
<body bgcolor=”cyan”>
<?php
$course = array (“Computer Science”=>”05″, “Commerce”=>”39″,”Science”=> “01” ); echo”The code of Computer Science is “.Scourse[“Computer Science”];
?>
</body>
</html>

Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP

Question 2.
Compare echo and print statements used in PHP.
Answer:
Output statements in PHP:
1. echo and print are used to display all types of data but echo is used to produce multiple outputs. Parenthesis is optional. Print returns true or false based on success or failure whereas echo doesn’t return true or false.
eg:
echo “ first output”, “second output”; or
echo (“ first output”, “second output”);
print “only one output”; .
or
print (“only one output”);
Eg.
<!DOCTYPE HTML> <head> <meta charset=”UTF-8″> <title>
This is a php page </title>
</head>
<body>
<?php
echo “This is first output”,” This is second output<br>”;
print “Only support single output”;
?>
</body>
</html>

Question 3.
List the main differences between GET and POST methods in form submitting?
Answer:
The main differences are given below.
Plus Two Computer Science Chapter Wise Questions and Answers Chapter 10 Server Side Scripting Using PHP img1

Plus Two Computer Science Server Side Scripting Using PHP Five Mark Questions and Answers

Question 1.
What are the additional steps involved to run PHP in your computer?
Answer:
Basics of PHP
A. Setting up the development environment

  • Step 1: Install a PHP compatible web Server(Eg. Abyss Web Server For Windows)
  • Step 2: Install PHP interpreter.
    After installing the webserver type http:// localhost in the address bar the following screen will be available.

B. Writing and running the script
Take a note pad and type the code , PHP code should begin with <?php and end with ?>. Save this file in the root directory of the web server with extension .php.
Step 1
Take a notepad and type the following and save it as first.php on C:\Abyss Web Server\htdocs.
<?php
echo” My first PHP web page”;
?>
Step 2
Start the webserver if it is off
Step 3
Type as “http://localhost/first.php” in the address bar.