Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

PHP QUESTIONS

1. Advantages of PHP

Ans:

i. Easy and simple to learn: PHP is simple and easy to learn


and code
ii. Open Source: it’s a open source and free of cost.
iii. Platform Independent: it work on any platforms / OS
iv. Database: easily and securely connect with database.
v. Support: it has great online support and community.
vi. Testing: PHP based application are easy to test.
vii. Maintenance: PHP framework used to make the easy
development and maintain the code.
viii. Security: it has built in features and tools for providing
security to web application.

2. State use of str_word_count() with syntax

Ans:

i. Str_word_count() it’s a string function.


ii. This function is use to count the words in string.
iii. This function accept “string” as parameter
iv. It returns the integer value of word count
v. Syntax:
a. Str_word_count(“string);
3. Define Serialization

Ans:

i. The process of converting object into a sequence of bits.


ii. By which we can easily stored in file, buffer and transmit
through network.
iii. We use Serialize() and unserialize() function for converting
object to sequence of bits and reverse.

4. Write syntax of creating cookie

Ans:

i. Setcookie(name, value, expire, path, domain, secure,


httponly);
ii. Where ‘name’, ‘value’, ‘expire’ are necessary parameter.
iii. Example:

$cookie_name = “user”

$cookie_value = “karan”

Setcookie($cookie_name, $cookie_value, time() + (86400))


// 86400 = 1day
5. Write syntax of connecting PHP webpage with MySQL

Ans:

i. We can connect webpage with MySQL using


Mysqli_connect() method.
ii. It has following arguments:
a. Hostname
b. Username
c. Password
d. Database_name
iii. It return connection variable.
iv. Syntax:
a. $connection_variable = mysqli_connect(“<hostname>”,
“<username>”, “<password>”, “<database_name>”);
v. Example:
a. $conn = mysqli_connect(“localhost”, “root”, ” ”, “mydb”);

6. Define GET and POST method.

Ans:

i. GET
a. this method is use to submit HTML form data.
b. This data collected by superglobal variable $_GET
ii. POST
a. This method also use to submit HTML form data.
b. This data collected by superglobal variable $_POST.

7. Define use of $ sign in PHP.

Ans:

i. This $ sign use to declare variable in php.


ii. We can declare the variable by giving $ sign then variable
name.
iii. Syntax: $<variable_name>
iv. Example: $a

8. Define use of for – each loop.

Ans:

i. For each loop is a loop use to iterate over array element by


element.
ii. It access each element of arrays.
iii. It mostly use for traversing and printing an array element by
element.
iv. Syntax:

foreach(<array_name> as <accessing_element>)

//body

}
v. Example:

$a = Array(10,20,30,40);

Foreach($a as $n)

Echo $n;

vi. Output:

10

20

30

40

9. Different between implode and explode.

Ans:

Implode Explode

It accept array as parameter It accept string as parameter

It return string as result It return array as result

It convert array into string It convert string into an array


It has 2 parameter It has 2 parameters
Separator, array Delimiter, string
Syntax Syntax
$<variable> = $<variable> =
implode(<seprator>,<array>); implode(<Delimiter>,<string>);
Example:
Example:

10. Write use of Array_flip().

Ans:

i. This method flips array’s key with values and vice versa.
ii. It makes array keys to value
iii. And values to keys of their respective.
iv. Syntax: array_flip(array)

11. Define Imagecolorallocate() function along with syntax.

Ans:

i. This inbuilt function of PHP use to set color to the image.


ii. It returns the color in RGB format.
iii. Syntax: < variable> = ImageColorAllocate(<image>, <red>,
<green>,<blue>);
12. State the use of cloning of an object.

Ans:

i. The clone keyword is used to create a copy of an object.


ii. If any properties was a reference to the another object, then
reference is copied.
iii. The copy will be point the same object.
iv. An object copy is created by using the __clone().
v. __clone() method can not be called directly when an object is
cloned , php will perform copy of all o the object’s
properties.

13. Define following terms.


i. Start a session.
ii. Destroy a session.

Ans:

i. Start a session:-
a. Session start using session_start() method.
b. The session_start() function first checks if a session is already
started and if none is started then it starts one.
c. Session variables are set with the PHP global variables
$_SESSION.
d. The $_SESSION[] variables ca be accessed during the
lifetime of session.
e. Example:
<?php
if(isset($_GET['b1']))
{
session_start();
$_SESSION["favcolor"]="green";
$_SESSION["favanimal"]="dog";

echo "<br>Session Variables are set!!!";

echo "<br><br>Favourite color is


".$_SESSION['favcolor'];
echo "<br>Favourite animal is
".$_SESSION['favanimal'];
}
?>
<html>
<body>
<form method="get">
<input type="submit" name="b1" value="Start
Session">
</form>
</body>
</html>
ii. Destroy a session.
a. Use To remove all global session variables and destroy
the session.
b. use session_unset() and session_destroy() functions.
c. Example:

<?php
if(isset($_GET['b1']))
{
session_unset();
session_destroy();
}
?>
<html>
<body>
<form method="get">
<input type="submit" name="b1"
value="Destroy Session">
</form>
</body>
</html>
14. List out database operations.

Ans:

i. Database is a collection of related data.


ii. We can organize large amount of data in database so that we
can easily access it. DBMS is a system software for creating
and managing databases.
iii. We can create, update, delete and modify the data.
iv. PHP will works with many databases like postgreSQL,
sybase, oracle and many more but most commonly used is
MYSQL database.
v. MYSQL database is free to use.
vi. PHP is very flexible with MYSQL database compared with
other databases.
vii. Data transfer between MYSQL and php is very smoothly and
flexible.

15. List out the features of php.

Ans:-

i. Open source :- It is open source, It is available in any


website.
ii. Platform independent :- It is platform independent, PHP code
executes any operating system. If we write a code on
windows and try to run it on Linux then it will executes the
code successfully.
iii. Simple and easy :- It is simple and easy to use.
iv. Database :- We can perform the database operations using
PHP.
v. Fast :- It is the fastest programming language.
vi. Support :- It has great online support and community.
vii. Scripting language :- It is a scripting language that support
script.

16. Write a syntax of any two PHP string fun.

Ans:

i. str_word_count():-

Syntax:
str_word_count(string)
ii. strlen():-

syntax:
strlen(string)
iii. strpos():-

Syntax:-
strpos(string,substring,n)

iv. strtoupper():
Syntax:
strtoupper(string)

17. How do you convert one variable type into another variable in
PHP?

Ans:

i. PHP provides a datatype function to get or set the datatype of


a variable .
i. Gettype():-It is used to check the datatype.
ii. Settype():-It is used to change the datatype.
ii. Syntax:-
i. Gettype($varible);
ii. Settype($variable,cast_operator);

18. How do you create array in PHP?

Ans:

i. An array can hold many values under a single name, and you
can access the values by referring to an index number
ii. In PHP, the array() function is used to create an array.
iii. In PHP, there are three types of arrays:
1) Indexed arrays - Arrays with a numeric index
2) Associative arrays - Arrays with named keys
3) Multidimensional arrays - Arrays containing one or
more arrays
iv. Syntax:-
$variable = array(List of array);

19. Difference between echo and print in PHP.

Ans:

echo Print
i. Echo outputs one or i. Print output only one
more strings or more string or arguments.
arguments.
ii. Echo has no return ii. Print has no return value
value of 1 so it can be used in
expression.
iii. Echo is faster than print iii. Print is slower than
echo
iv. No written with iv. It can or cannot be
paranthesis written with paranthesis
v. Syntax: v. Synytax:
Echo $arg1, $arg2; Print($arg)
20. Describe the string operation in PHP with example.

Ans: There are 2 String operations:-

a. “ . ” :- (concatenation)
i. It is used to add/join more than one strings.
ii. Syntax:-
$a= “string_1”;
$b = “string_2”;
$c = $a.$b;

b. “ .= ” :- (concatenation and then assign)


i. It joins strings and assign the value to the left
hand variable.
ii. Syntax:-
$a= ”Hello “;
$a .= “Welcome”;
echo $a;

21. List attribute of cookies.

Ans:

i. setCookie(name,value,expire,path,domain,secure,httponly);
ii. Only the name parameter is required, all other parameters are
optional.

name - name of the cookie.


value - value of the cookie

expiry - time when cookie will get expire.

path - This specifies the directories for which the cookie is valid.

domain - The browser will return the cookie only for URLs
within this domain.The default is the server host name.

Secure - This can be set to 1 which specify that the cookie


should sent by using HTTPS otherwise set to 0 which means
cookie can be sent by using HTTP protocol.

22. List any two feature of Mysql.

Ans:

i. MYSQL is open source RDMBS.


ii. MYSQL database is free to use.
iii. MYSQL handles more expensive and powerful database
packages.
iv. PHP is very flexible with MYSQL database compared with
other databases.

23. How to create class in PHP.

Ans:

i. Class is create using class keyword.


ii. Then give classname and crate class and followed by curly
braces
iii. Syntax: Class Declaration
-------------------------
class ClassName{
// attributes and methods (properties)
}
Example:

class Student{
function getdata(){
$roll=1010;
$name="Dennis";
$marks=98.99;
}
function display(){
print("Student Roll No:". $roll);
print("Student Name:". $name);
print("Student Marks:". $marks);
}

}
24. How can you view the structure of a table?

Ans:

i. To view the structure of the table we use “select” query.


ii. Query Syntax:- “SELECT * FROM table_name”;
iii. To run the query we use mysqli_query() method.
iv. Example:-

<?php

$conn=mysqli_connect(“localhost”, “root”, “”,


“mydb”);

if(!$conn){

echo “Unable to connect the database ”;

else{

$query = “SELECT * FROM user1”;

$result = mysqli_connect($conn, $query);

If($result){

while($row = mysqli_fetch_assoc($result)){

echo $row[‘col_name_1’];

echo $row[‘col_name_2’];

}
}

?>

25. Write full form of PHP.

Ans:

PHP stands for Hypertext preprocessor.

Also known as Personal Home Page.

26. How to create object in PHP.

Ans:

i. Object is an instance of user defined class.


ii. Once class is created then we can create no of objects.
iii. We can access members of the class using -> symbol.
iv. Syntax: Object Creation
$ObjectName= new className();
v. Example:
$s1= new Student();
$s1 -> method_student(); // method of class student
27. What are the role of server in PHP?

Ans:

i. PHP is a server-side scripting language that allows the client


to receive output on the processing that happen within the
server.
ii. Since this processing is completed by using the resources of
the server, when a request is filled, it sends the HTML back
to the browser

28. List any four datatypes in Mysql.

Ans:

i. CHAR(size)
ii. VARCHAR(size)
iii. INT()
iv. DECIMAL()
v. FLOAT()
vi. DATE()
vii. DATETIME()
29. List out Logical operator that used in PHP.

Ans:

i. Logical AND(&&,and) : True if both sides are true otherwise


false
ii. Logical OR(||,or) : False if both sides are false otherwise true
iii. Logical XOR(xor) : If both sides are identical then it is false
otherwise TRUE
iv. Logical NOT (!) : Reverse the result

30. Difference between session and cookie.

Ans:

cookie Session
Small pieces of data sent from A temporary and interactive
website and stored on the user’s information interchange between
computer by the user’s browser two or more communicating
while the user is browsing devices or between a computer or
user.
Stored in the client’s browser as Stored in the server side
text files.
Can store a minimum amount of Can store a large amount of data
data
Provide minimum security Provide more security beacuase it
beacuase it is easier to access is difficult to access session value
cookies value

Do not hold multiple variables. Hold multiple variables


Keep information until deleted by Available until the browser is
the user or set as per the timer. opened.
Comparatively less reliable More reliable.

31. Explain $_GET and $_POST variable in PHP.

Ans

$_GET:-

i. The data send to the server, we can retrive by using php


variable $_GET.
ii. The GET method is used to submit the HTML form data.
This data is collected by the predefined $_GET variable for
processing

$_POST:-

i. The data send to the server, we can retrive by using php


variable $_POST.
ii. the POST method is also used to submit the HTML form
data. But the data submitted by this method is collected by
the predefined superglobal variable $_POST
32. Describe final method and final class.

Ans:

Final class:

i. A class declared as final cannot be extended in future.


ii. Once a class declared as final then that class should not
be inhdeited due to security.
iii. It contain final or non-final methods,nut there is no use
of final method in class.
iv. The final keyword can be used to prevent class
inhertinace and class overriding.

Final method:

i. Method is declared as final then overriding on that


method can not be performed

33. Explain difference datatypes in PHP.

Ans:

i. Integer:
i. It is a collection of 0 to 9 digits combination value without
decimal points.
ii. You can represent Integer number in decimal,octal and
hexadecimal format.
iii. If it is decimal, it is just the number.
For example: 145
iv. In PHP, we can test whether value is int or not by using
is_int() or is_integer()
v. Example:
<?php
//Integer data Type
$num=0x34;
if(is_int($num))
{ echo "Number is integer"; }
Else
{ echo "Number is not integer"; }
?>
ii. Floating Point Number:
i. Floating point number is called as real number.
ii. It is a collection of 0 to 9 digits combination value with
decimal points.
iii. In PHP, floating point number will display value upto 15
digits decimal places.
iv. You can represent floating point number using two
different format.
I) Fractional Format : 23.45, 67.8, 143.78
II) Exponential Format: 1.3E-56, 2.3E89
v. In PHP, we can test whether value is float or not by using
is_float() or is_real()
vi. Example:
<?php
//float data Type
$num=3.14;
if(is_float($num))
{
echo "Number is float";
}
Else
{
echo "Number is not float";
}
?>
iii. String:
i. Collection of characters is known as String.
ii. We can represent string using single or double quotes.
iii. PHP provided method is_string() to check whether given
value is string or not.
iv. Exmple:
<?php
$name="VJTech";
//echo "My class name is $name";
if(is_string($name))
{
echo "$name is String";
}
else
{
echo "$name is not String";
}
?>
iv. Boolean:
i. Boolean value can be either TRUE or FALSE
value.
ii. Both values are case-insensitive.
iii. is_bool() method used to check whether value is
boolean or not.
iv. Example:
<php
$m=true;
if(is_bool($m))
{
echo "$m is Boolean";
}
Else
{
echo "$m is not Boolean";
}
?>
v. Arrays:
i. Array is used to store multiple values in single variable.
ii. In PHP,Collection of different types of values is known as
Array.
iii. Array index should begin with 0 and end with SIZE-1.
iv. We can retrive the individual array elements using subscript
and index number.
v. Example:
<?php
$p=array('a','b','c','d');
$q=array('first'=>'10','second'=>'20','third'=>'30');
echo "Value of p array 0 index = $p[0]";
echo "Value of p array 1 index = $p[1]";
echo "Value of p array 2 index = $p[2]";
echo "Value of q array = ".$q['first'];
echo "Value of q array = ".$q['second'];
echo "Value of q array =".$q['third'];
?>
34. Explain different types of array in php.

Ans:

In PHP, there are three types of arrays:

1) Indexed arrays :-
i. There are two ways to create indexed arrays.
ii. The index can be assigned automatically(index always
starts at 0),
$cars = array("Volvo", "BMW", "Toyota");
or the index can be assigned manually:
$cars[0] = "Volvo";
$cars[1] = "BMW";
$cars[2] = "Toyota";

2) Associative arrays :-
i. Associative arrays are arrays that use named keys that you
assign to them.
ii. There are two ways to create an associative array:
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
$num = array("a"=>123,"b"=>345,"c"=>789);
or:
$age['Peter'] = "35";
$age['Ben'] = "37";
$age['Joe'] = "43";
iii. Example:
<?php
$num = array("a"=>123,"b"=>345,"c"=>789);
echo "Array Elements are ".$num['a']." ".$num['b']."
".$num['c'];
?>
3) Multidimensional arrays :-
i. Arrays containing one or more arrays.
ii. Values in the multi-dimensional array are accessed
using multiple index.
iii. Example:
$a=array(10,20,30);
$b=array(40,50,60);
$c=array(70,80,90);
$multiArray=array($a,$b,$c);
$x=multiArray[2][1];

35. Why var_dump() prefer over print_r().

Ans:

The var_dump() function displays structured information about


variables/expressions including its type and value. Whereas the
print_r() displays information about a variable in a way that’s
readable by humans.
36. Explain bitwise operator with example.

Ans:

I) Bitwise AND (and) : If both bits are 1 then output would be 1


otherwise 0
II) Bitwise OR(|) : If both bits are 0 then output would be 0
otherwise 1
III) Bitwise XOR (^) : If both bits are same then output would be
0 otherwise 1
IV) Bitwise NOT(~) : Change 1 to 0 or 0 to 1
V) Bitwise Left Shift(<<)
VI) Bitwise Right shift(>>)
VII) Example:
<?php
$a=12;
$b=13;
$c=$a and $b;
echo "Bitwise AND = $c"; $c=$a | $b; echo "
Bitwise OR = $c";
$c=$a ^ $b;
echo "Bitwise XOR = $c";
$c=~12;
echo "Bitwise NOT = $c";
$c=14<>2;
echo "Bitwise right Shift = $c";
?>
4 marks question
1. Explain indexed and associative array with example:

Ans:

i. Indexed Array:
a. In this type of array we enter the elements with respect to
index.
b. In it each element has its own unique index.
c. This indexes starts from 0
d. We can access the element of this array using this
indexes.
e. Example:
i. $arr = array([0] => ‘karan’, [1] => ‘bhale')

ii. Associative Array:


a. In this type of array we have keys and values.
b. Each element of this array refers to value
c. And each value has its own unique key.
d. This keys are strings.
e. Example:
i. $arr = array([‘0’] => ‘karan’, [‘1’] => ‘bhale')

2. Define introspection and explain with example:

Ans:
i. It’s a ability of program to examine object characteristics.
ii. Such as its name, parent class, classes, interface etc.
iii. PHP has large number of functions for this task.
iv. Following are functions of introspection:
a. Class_exists(): checks whether class is present or not.
b. Et_class(): return class name of object
c. Get_parent_class(): return parent class of object’s class.
d. Is_subclass_of(): checks whether given object has
given parent class.
e. Get_class_vars(): Return default properties of class.
f. Interface_exists(): check whether interface defined
3. Session vs cookies:

Ans:

Session Cookies

Session stores its values on the Cookies stores on clint side in


server text file
session stores the unlimited cookies stores the limited amount
amount of data of data
We can stores about 128MB size
We can store about 4kb size data
data
Cookies destroyed when its
Session destroyed using
specified time is over or by giving
session_destroy() method
negative time to it.
Session variable access using Cookies variable access using
$_SESSION variable $_COOKIE variable
We starts the session using We not need to call any function
session_start() method to start cookie.
There is no method for setting There is setcookie() method
session variable which we use to set cookies

More secure Less secure


4. implode vs explode:

Ans:

Implode Explode

It accept array as parameter It accept string as parameter

It return string as result It return array as result

It convert array into string It convert string into an array

It has 2 parameter It has 2 parameters


Separator, array Delimiter, string
Syntax Syntax
$<variable> = $<variable> =
implode(<seprator>,<array>); implode(<Delimiter>,<string>);
Example:
Example:
5. write a program for cloning a object

Ans:

<?php

class Area

public $radius;

function get_radius(){

$this->radius=readline("Enter Radius of Circle:");

class Circle extends Area

var $PI;

function Calc_Area_Of_Circle()

$this->PI=3.14;

$Area=($this->PI*$this->radius*$this->radius);

echo "\nArea of Circle = $Area";

}
$c1=new Circle();

$c2=clone $c1; //c2 object is a copy of c1 object

$c1->get_radius();

$c2->Calc_Area_Of_Circle();

?>

6. define session and explain how it works

Ans:

i. php session is use to store and pass the information from one
page to another securely.
ii. It’s a user data which is store on a server side.
iii. Sessions provides a security to user profile.
iv. Php session creates unique id for each browser to recognize
the user.
v. We can start session in php using session_start() method.
vi. After this method we can set our session variables using this
$_SESSION super global variable.
vii. This variable use to access session variables.
viii. We can unset all session variables using session_unset()
method
ix. Then we can destroy the session using session_destroy()
method.
x. Example:
7. Write update and delete operation on table data

Ans:

i. Update operation:
a. We can update the data of table using this operation.
b. We use update query for doing this operation.
c. Syntax: Update <table_name> set <column_name> =
<value> where <condition>;
d. Example:

Update data set name = ‘karan’ where id = 2

ii. Delete operation:


a. We can delete the data from table using this operation
b. We use Delete query for doing this operation.
c. Syntax: delete * from <table_name> where <condition>
d. Example:

Delete * from data where id = 2


8. State variable function with example

Ans:

i. Var_dump():
a. Dumps the information about one or more variable:
b. Syntax: var_dump(<variable>)
c. Example:

$a = 10;

Echo var_dump($a);

d. Output: int(10)
ii. Is_int():
a. Checks whether the variable is integer.
b. Syntax: is_int(<variable>)
c. Example:

$a = 20;

Echo is_int($a);

d. Output: 1
iii. Is_float():
a. Check whether the variable is float
b. Syntax: is_float(<variable>)
c. Example:

$a = 10.20;

Echo is_float($a);
d. Output: 1
iv. is_null():
a. checks the variable is null or not
b. Syntax: is_null(<variable>)
c. Example:

$a = null;

Echo is_null($a);

d. Output: 1
v. is_iterable():
a. checks the content of variable is iterable or not
b. Syntax: is_iterable(<variable>)
c. Example:

$a = array(10,20,30);

Echo is_iterable($a);

d. Output: 1

9. Explain concept of serialization with example

Ans:

i. Definition:
a. The process of converting object into a sequence of bits.
b. By which we can easily stored in file, buffer and transmit
through network.
c. We use Serialize() and unserialize() function for
converting object to sequence of bits and reverse.
ii. Serialize() function:
a. It return bit wise sequence of given object. In string format
b. Syntax: serialize(<variable>);
c. Example: $a = “karan”;

$ser = serialize($a);

Echo $ser;

d. Output:

I:0,s:5:”karan”;

iii. unSerialize():
a. it return the normal variable value.
b. It convert serialize string into actual value.
c. Syntax: unserialize(<variable>);
d. Example: $a = “karan”;

$ser = serialize($a);

$norvar = unserialize($ser);

Echo $norvar;

e. Output:

Karan
10. Explain insertion of data and retrieving data from table

Ans:

I. Insertion:
a. Using this operation we can add data in table.
b. Using this operations we can add data in particular column
or in all column.
c. For this we use insert query of SQL.
d. Syntax:
i. Insert into <table_name> values (<values>);
ii. Insert into <table_name> <column_names> values
(<values>);
e. Example: insert into data (name,age) values (‘karan’, 20);
II. Retrieving:
a. Using this operations we can retrieve data from table.
b. We can get this values in form of associative array.
c. For this we use ‘select query’ of SQL
d. Syntax:
i. Select * from <table_name>;
ii. Select <column_names> from <table_name>;
e. Example: select * from data;
11. Create webpage using GUI component

Ans:

<html>

<body>

<form action="" method="GET">

Name:<input type="text" name="nm"></br><br>

Enter Your Address: <textarea name="tf1" rows=10


cols=50></textarea>

Please select your Gender:

<input type="radio" name="gender" value="Male">Male

<input type="radio" name="gender" value="Female">Female

<input type="radio" name="gender" value="Other">Other

<h3>Select your interested programming language:</h3><br>

<input type="checkbox" name="c1[]" value="C Lang">C


Lang<br><br>

<input type="checkbox" name="c1[]" value="C++


Lang">C++ Lang<br><br>

<input type="checkbox" name="c1[]" value="JAVA


Lang">JAVA Lang<br><br>

<input type="checkbox" name="c1[]" value="Python


Lang">Python Lang<br><br>
Password:<input type="text" name="psw"><br><br>

<input type="submit" name="b1" value="Login">

</form>

</body>

</html>

12. Describe the creation of PDF document in PHP

Ans:

i. For creating PDF in php we need FPDF file.


ii. We can download this file from FPDF.org
iii. Then after this we include FPDF.php file in our current php file.
iv. Then we need to create pdf variable.
v. Then we can add pages in pdf using AddPage() method.
vi. We can write then in pdf using write() function or ceil()
function.
vii. Then after all operations for seeing the output we use output()
method.
viii. Example:

<?php

Include “FPDF/fpdf.php”;

$pdf = new FPDF();

$pdf->AddPage();

$pdf -> ceil(80,10,”karan bhale”);

$pdf ->output();
13. Describe following string functions:
a. Str_replace():
b. Ucword():
c. Strlen():
d. Strtoupper():

Ans:

i. Str_replace():
a. This function use to replace current characters of string to
new one.
b. In it we need to specify current sub string, new sub string,
original string.
c. Syntax:
i. Str_replace(<find>, <replace>, <original_string>,
count);
ii. Ucword():
a. This function use to convert given sentence into sentence
case.
b. In it first character of each word become capital.
c. Syntax: ucword(<string>);
iii. Strlen():
a. This function return the length of string.
b. In it we need to specify the string. And get integer value in
return.
c. Syntax: strlen(<string>);
iv. Strtoupper():
a. This function use to convert given string in to upper case.
b. In it we specify original string and get new string in
uppercase.
c. Syntax: strtoupper(<string>);

14. Describe anonymous function in details

Ans:

15. Write program to create fill rectangle in php

Ans:

<?php

// Create an image of given size


$image = imagecreatetruecolor(500, 300);
$green = imagecolorallocate($image, 0, 153, 0);

// Draw the rectangle of green color


imagefilledrectangle($image, 20, 20, 480, 280, $green);

// Output image in png format


header("Content-type: image/png");
imagepng($image);

// Free memory
imagedestroy($image);
?>
16. Describe cookies:

Ans:

i. Cookies:
a. Cookies are small piece of data sent from browser and
stored on user side.
b. It stored in text file.
c. It only stays until its expiration period.
d. We can set its expiration period while declaring it.
ii. How to set cookies:
a. For setting cookies we use setcookies() method.
b. Here we give name, value, time, path as parameters
c. Syntax: setcookies(<name>, <value>,<time>,<path>);
iii. How to modify cookies:
a. For modifying cookies we use $_COOKIE super global
variable
b. Using this we can modify and access the cookies values.
c. Syntax: $_COOKIE[<cookie_name>];
iv. How to delete cookies:
a. For deleting cookies we reduce their expiration period.
b. Such as we give a negative time for cookie so that it can
delete automatically.
17. Describe web page validation with example:

Ans:

i. In it we validate the UI components of forms.


ii. Here we checks whether form is properly filled or not.
iii. We checks whether necessary fields are filled or not.
iv. We checks is given input is in proper format or manner.
v. We check whether user gives proper input or not.
vi. We use following functions for web page validation:
a. Empty(): this method checks whether given field is
empty or not
b. Preg_match(): this method checks whether given input is
in proper format or not
c. Is_numeric(): this method checks whether given value is
numeric or not.
vii. Example:

18. Write program using mysqli_connect()

Ans:
19. Explain implode explode function in php

Ans:

i. Implode:-
a. This function use to convert array into string.
b. This function in php use to join element of an array
with string.
c. It creates string from array.
d. This function join array elements with sep(separator)
string.
e. Syntax:
string implode(string sep,array $name);
f. Example:-
<?php
$city=array("Pune","Thane","Nashik","N
agar","Tasgaon"); $str=implode("-
",$city);
echo "String Values : $str";
?>
ii. Explode:-
a. It breaks string into smaller part and strored it in an
array.
b. To convert string into an array we use explode
function.
c. This function split the string based on the delimiter
and return an array.
d. - Syntax:
array explode(string $delimiter,string str[,int
$limit]);

e. $str="one|two|three|four|five";
$NumArray=explode("|",$str);
print_r($NumArray);

20. Write php program to create calculator using switch case.

Ans:

21. Write a concept of overloading in detail with example

Ans:

i. polymorphism is a property of object oriented programming


ii. we use method overloading concept to achieve polymorphism in
our program.
iii. Function overloading helps us to achieve compile time
polymorphism
iv. For PHP we use magic method __call()
v. Which has 2 parameters function_name, and array of arguments.
vi. This magic method calls when object calls a method which
doesn’t exist.
vii. Syntax:
function __call(<function_name>, <argument array>){

//body

viii. Example:
<?php
Class shape{
Function __call($name, $args){
If($name == ‘area’){
Switch(count($args)){
Case 0 : return 0;
Case 1: return args[0] * args[0];
Case 2: return args[0] * args[1];
}
}
}

$S = new shape();

$ar = s->area(5);

Echo(“area is: $ar”);

$ar = s->area(5,10);

Echo(“area is: $ar”);

ix. Output: area is: 25


Area is: 50
22. Write a concept of overloading in detail with example

Ans:

You might also like