Preprocessor hyper text interview question with answers

Posted by Unknown at 18:17
What operation we can perform with Cookie?Explain it?


Ans:We can create the cookie,retrieve heir value and destroy them.Creating a cookie: Using setcookie() function we can create a cookie.
Example:
<?php
setcookie("client", "Abhi", time()+3600);
?>
Ques: 62 What you know about Cookie?
Ans:We use cookie to authenticate the client.Cookie file is attached with the client computer browser.Every time client computer sends the requested page with their cookies.Their is advantage in PHP.In this we can create and retrieve the cookies values. We can create the cookie using setcookie () function. Syntax: setcookie(Cookie_Name, Cookie_Value, expire_time, path, domain);
Ques: 63 How we use fopen(),fclose(),feof(),fgets() and fgetc()in PHP? 
Ans:
fopen() function is use to open a file in a specific mode(read write etc.).
<html>
<body>
<?php
$R4R_file=fopen("R4R Welcome.doc","r");
?>
</body>
</html>
fclose() function is use to close the file.
<?php
$R4R_file = fopen("R4R Welcome.doc","r");
//block of code
fclose($R4R_file);
?>
feof() is used to confirmed that 'end-of-file' has been achieved.
if (feof($R4R_file))
echo "End of file";
fgets() is used when we want to read a single line from the file.
<?php
$R4R_file = fopen("R4R Welcome.doc", "r") ;
while(!feof($R4R_file))
{
echo fgets($R4R_file). "<br />";
}
fclose($R4R_file);
?>
fgetc() is used when we want to read a single character from the file.
<?php
$R4R_file=fopen("R4R Welcome.doc","r");
while (!feof($R4R_file))
{
echo fgetc($R4R_file);
}
fclose($R4R_file);
?>
Ques: 64 What types of modes we use in PHP for File Handling?
Ans:Some modes that we use in PHP are given below:
1.r :This perform only read operation and start at the beginning of file.
2.r+ :This perform both read and write operation and start at the beginning of file.
3.w :This perform only write operation.we can open and create the content of file.If file is not exist creates a new file.
4.w+ :This perform both read and write operation. we can open and create the content of file.If file is not exist creates a new file.
5.a :We can open and append the content of file.If file is not exist creates a new file.
tion.Also create new files.It will show error or retur
6.a+ :We can open,read and append the content of file.
7.x :This perform only write oper
an False when file is already exist.
operation. Also create new files.It will show error or return False when file is already exist.
8.x+ :This perform both read and writ
e
Ques: 65 How to use File Handling in PHP? 
Ans: We Done File Handling in PHP by using fopen() function.
Example:
<html>
<?php
<body>
"r"); ?> </body> </html> first par
$file=fopen("R4R Welcome.doc"
,ameter of fopen use for which file you want to open and the second parameter use for which mode you want to perform on that file(Like:read,write,append etc).
Ques: 66 How we use include() and require() function in PHP?
Ans: When we use include() function it will contain all the text into a file and this will send to a file when we use include() function.

Example:
<html>
<body>
<?php
include("CorruptFile.php");
echo "R4R Welcomes You!";
?>
</body>
</html>
By using include() function is use to include the header file in a page.It will generate warning but not stopped the execution of JavaScript. When we use require() function it will contain all the text into a file and this will send to a file when we use require() function.Example:
<html>
<body>
<?php
require("CorruptFile.php");
echo "R4R Welcomes You!";
?>
</body>
</html>
It will generate warning and also stopped the execution of JavaScript.
Ques: 67 Why we used Server Side include function?
Ans:We use Server Side Include(SSL) to create functions,footer,header or elements.For multiple reuse those on different pages.In this we uses two functions include() and require().Both functions are same except how they handle errors.

1.include() function
2.require() function
1.include() function:When error comes it show warning but not stop the execution of JavaScript.
2.require() function:When error comes it show fatal error and also stop the execution of JavaScript.
Ques: 68 Why we use Date() function in PHP and How?
Ans: We use Data() function in PHP to format the local time and date.

Syntax:
string date( string $format[, int $timestamp ])
Where,timestamp is optional.Timestamp is the no of seconds after 1st Jan,1970 at 00:00:00 GMT.
Example:
<?php
echo Date("Year/month/date");
echo "<br />";
echo Date("Year.month.date");
echo "<br />";
echo Date("Year-month-date");
?>
Ques: 69 Why we use $_REQUEST variable?
Ans:


We use $_REQUEST variable in PHP to collect the data_values from $_GET,$_POST and $_COOKIE variable.
Example:
R4R Welcomes You <?php echo $_REQUEST["name"]; ?>.<br />
You are <?php echo $_REQUEST["age"]; ?> years old!
Ques: 70 When we used $_GET and $_POST variable?
Ans: We know that when we use $_GET variable all data_values are display on our URL.So,using this we don't have to send secret data (Like:password, account code).But using we can bookmarked the importpage.

We use $_POST variable when we want to send data_values without display on URL.And their is no limit to send particular amount of character.
Using this we can not bookmarked the page.
Ques: 71 How we used $_get and $_post variable in PHP?
Ans:
$_get is used to retrieve the data_values by using HTTP GET method.When we send the data from get method it will display on URL.It has also a limit to send variables.You can send maximum 100 character from GET method.
Example:
<form action="R4R Welcome.php" method="get"><input type="hidden" name="phpMyAdmin" value="f43d4e0b88acea2d2a393515f6bf38f2" /><input type="hidden" name="phpMyAdmin" value="70ac9566533a2665b6597346aab7f985" />
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
When we press submit button than it will send this information on URL.
http://www.capptitudebank.blogspot.com/Welcome.php?name=Abhi&age=22
And data_values will collect on R4R Welcome page using $_GET variable.
R4R Welcomes You<?php echo $_GET["name"]; ?>.<br />
You are <?php echo $_GET["age"]; ?> years old!

We uses $_post variable to send the array of variable names with their data_values using HTTP POST method.When we send data_values from post method than it will not display the data_values on URL & their is no limit to send data_values.
Example:
<form action="R4R Welcome.php" method="post"><input type="hidden" name="phpMyAdmin" value="f43d4e0b88acea2d2a393515f6bf38f2" /><input type="hidden" name="phpMyAdmin" value="70ac9566533a2665b6597346aab7f985" />
Name: <input type="text" name="name" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
When we pressed submit button than URL is looking like that,
http://www.capptitudebank.blogspot.com/R4R Welcome.php
means that it not display the data_values that you enter.And data_values will collect on R4R Welcome page using $_POST variable.R4R Welcomes You <?php echo $_POST["name"]; ?>.<br />You are <?php echo $_POST["age"]; ?> years old!
Ques: 72 What is form validation?What is Client Side and Server Side validation?
Ans:If programmer created a file it should be properly validate.Using form validation we can stop the processing of incorrect input.Because when user enter a invalid input than it may be our form will processed and generated wrong input.
We can validate our form on two sides.
1.Client Side
2.Server Side
In Client Side we validate form using only JavaScript.In Server Side we create backup for that case when user off the JavaScript of web page or maybe if you uses different web Browsers because they can generate different output of JavaScript that you have written.
Client Side validation is much faster than Server Side validation.
Some general value that you have to validate when you create form.
1.empty values
2.numbers only
3.input length
4.email address
5.strip HTML tags
Ques: 73 How to handle form in PHP?
Ans:
When we handle form in PHP keep that most important
thing any form element of HTML page will be automatically goes on PHP scripts.
Example:
<html>
<body>
<form action="R4R Welcome.php" method="post"><input type="hidden" name="phpMyAdmin" value="f43d4e0b88acea2d2a393515f6bf38f2" /><input type="hidden" name="phpMyAdmin" value="70ac9566533a2665b6597346aab7f985" />
Name: <input type="text" name="Name" />
Password: <input type="password" name="Password" />
<input type="Submit" />
</form>
</body>
</html>
When this code is executed.The value of both fields are display on R4R Welcome.php page. Automatically generated code on R4R Welcome page are:
<html>
<body>
R4R Welcomes You <?php echo $_POST["Name"]; ?>.<br />
Your password is <?php echo $_POST["Password"]; ?>
</body>
</html>
Output:
R4R Welcomes You Abhi.
Your password is love.
Ques: 74 What do you understand functions in PHP?How we create them?  
Ans:
Functions are one the main property in PHP.It makes PHP useful as compare to others.PHP provides more than 701 in-build functions.
How to create Functions in PHP:For creating functions in PHP we have to keep in mind these steps.
Step1.To start PHP function with function().
Step2.Suppose if we want set name of function than we can write that after function.?But function name should start with letter or underscore'_'.
Step3.After creating PHP function we open a curly brace'{'.
Step4.After that write a block of code.
Step5.Close PHP function with closed curly brace'}'.
When we follow these steps than definitely PHP function will created.
Example:
<?php
function name()
{
echo "Abhi";
}
name();
?>
Ques: 75 How to use while,do..while,for and foreach loop in PHP?
Ans:
Below I have given u how to use while, do.while, for and foreach loop in PHP.
1.while:Uses, we want to execute a line of code many times till specific condition is true.
Syntax:
while (condition)
code will be executed;//When condition is true
Example:
<html>
<body>
<?php
$m=3;
while($3<=6)
{
echo "Number is " . $m . "<br />";
$m++;
}
?>
</body>
</html>
2.do..while:Uses, we want to execute a block of code at least one time. After that it checks the condition, till its correct the block of code will executed.Otherwise stopped the execution.
Syntax:
do
{
code will be executed;
}
while (condition);//loop execute atleast one time whenever condition is true or false
Example:
<html>
<body>
<?php
$m=2;
do
{
$m++;
echo "Number is " . $m . "<br />";
}
while ($m<7);
?>
</body>
</html>
3.for:Uses, When we want execute a block of code for some specific times.
Syntax:
for (initialize; condition; increment/decrement)
{
code will be executed;
}
Example:
<html>
<body>
<?php
for ($m=2; $m<=4; $m++)
{
echo "R4R Welcomes You!<br />";
}
?>
</body>
</html>
4.foreach:Uses, When When we want execute a block of code for each element in an array.
Syntax:
foreach (array as value)
{
code will be executed;
}
Example:
<html>
<body>
<?php
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
echo "Value: " . $value . "<br />";
}
?>
</body>
</html>

Ques: 76 What do you understand about looping in PHP?
Ans:
Looping uses, when we want to execute some block of code for a specific time.In PHP Looping are of Four types:
1.while
2.do..while
3.for
4.foreach
We uses 'while', when we want to execute a block of code till given condition is true.
We uses 'do..while', when we want to execute a block of code at least one.After that it checks the condition if it is true than block of code is execute till condition is true,Other wise stopped the execution.
We uses 'for', when we want to execute a block of code many times.
We uses 'foreach', when we want to execute a block of code for each element in an array.
Ques: 77 What do you understand about Numeric array, Associative array and Multidimensional array?
Ans:
Here, I explain Numeric array, Associative array and Multidimensional array in detail:
1. Numeric array:In this array we entered each array element with a unique key.Below I have given you examples how to use Numeric Arrays in PHP.
Example:
<?php
$p_names = array("vivek","abhi","ankit","nik");
echo $p_names[0] . " ," . $p_names[1] . " . $p_names[2] . " and " . $p_names[3] . " are friends";
?>
'OR'
<?php
$names[0] = "vivek";
$names[1] = "abhi";
$names[2] = "ankit";
$names[3] = "nik";
echo $p_names[0] . " ," . $p_names[1] . " . $p_names[2] . " and " . $p_names[3] . " are friends";
?>
2.Associative array:In this array we assign array elements with unique key and their respected values.Below I have given you examples how to use Associative Arrays in PHP.
Example:
<?php
$marks['vivek'] = "90";
$marks['abhi'] = "80";
$marks['ankit'] = "85";
echo "vivek scored" . $marks['vivek'] . " percent in CAT exam.";
?>
Output:
vivek scored 90 percent in CAT exam.
3.Multidimensional array:In this array we can declare array with in an array.
In this multiple arrays has a automatically assign unique key.Below I have given you examples how to use Multidimensional Arrays in PHP.
Example:
<?php
$families = array
(
"Agarwal"=>array
(
"vivek",
"vineet",
"abhi"
),
"Patel"=>array
(
"hariom"
),
"Singh"=>array
(
"saurabh",
"ram",
"rohan"
)
);
echo "Is " . $families['Agarwal'][0] .
" belongs to the Agarwal family?";
?>
Output:
Is vivek belongs to the Agarwal family?

Ques: 78 What do you understand array in PHP?
Ans: We create array in PHP to solved out the problem of writing same variable name many time.In this we create a array of variable name and enter the similar variables in terms of element.Each element in array has a unique key.Using that key we can easily access the wanted element.Arrays are essential for storing, managing and operating on sets of variables effectively. Array are of three types: 1.Numeric array 2.Associative array 3.Multidimensional array Numeric array is used to create an array with a unique key.Associative array is used to create an array where each unique key is associated with their value.Multidimensional array is used when we declare multiple arrays in an array. Ques: 79 How to use Switch statement in PHP?
Ans:
If you want to execute more than one code than we use Switch statement.
Syntax:
switch (expression)
{
case label1:
code to be executed if expression = label1;
break;
case label2:
code to be executed if expression = label2;
break;
default:
code to be executed
if expression is different
from both label1 and label2;
}
In this One expression is execute one time.We match a particular value.If it is matched than its correspondent case will executed.When break comes executed case will stopped and command go on next case.If none of the case are executed than default case will executed.
Example:
<html>
<body>
<?php
switch ($m)
{
case 1:
echo "Number One";
break;
case 2:
echo "Number Two";
break;
case 3:
echo "Number Three";
break;
default:
echo "No number between One and Three";
}
?>
</body>
</html>

Ques: 80 How we use if..else and elseif statement in PHP?
Ans:
If..else statement is used where we want to execute some code if condition is true otherwise execute some other code.
Syntax:
if (condition)
code to be executed;//when condition is true
else
code to be executed;//When condition is false
Example:
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Weekend!";
else
echo "Today!";
?>
</body>
</html>

Elseif statement is used where we want to execute some code if multiple conditions are true.
Syntax:
if (condition)
code to be executed;//condition is true
elseif (condition)
code to be executed;//condition is true
else
code to be executed;//condition is false
Example:
<html>
<body>
<?php
$d=date("D");
if ($d=="Fri")
echo "Weekend!";
elseif ($d=="Sun")
echo "Sunday!";
else
echo "Today!";
?>
</body>
Ques: 81 Tell me about PHP operator?
Ans:
PHP provide us many operator. These are:
1.Arithmetic Operator
2.Assignment Operator
3.Comparison Operator
4.logical Operator

1.Arithmetic Operator:Some arithmetic operators are given below,
Addition('+') m+4 , 8(given m=4)
Subtraction('-') m-4, 4(given m=8)
Multiplication('*') m*4, 8(given m=2)
Division('/') m/4, 2(given m=8)
Modulus (division remainder)('%') m%2, 1(given m=3)
Increment('++') m++, m=5(given m=4)
Decrement('--') m--, m=6(given m=5)

2.Assignment Operator: Some assignment operations are given below,
= m=n
-= m-=n or m=m-n
*= m*=n or m=m*n
/= m/=n or m=m/n
.= m.=n or m=m.n
%= m%=n or m=m%n
+= m+=n or m=m+n

3.Comparison Operator:Some comparison operators are given below,
==(is equal to) 2==5returns false
!=(is not equal to) 2==5returns true
>(is greater than) 2==5returns false
<(is less than) 2==5returns true
>=(greater than or equal to) 2==5returns false
<=(is less than or equal to) 2==5returns true

4.Logical Operators:Some logic operators are given below:
&&(and) (m<4 && n>2)returns true(given m=3,n=5)
||(or) (m=4 && n=4)returns false(given m=5,n=6)
!(not) !(m==n)returns true(given m=2,n=3)
Ques: 82 What is the use of strlen() and strpos() functions?
Ans:
strlen() function is used to find out the length of the given string. Example: <?php echo strlen("R4R Welcomes you!"); ?> output: 17 strpos() function is used to match a character or word from the given string.And return the position of the character or word. Example:This program return the position of 'you'. <?php echo strpos("R4R Welcomes you","you"); ?> output: 13 Correct answer is 13 not 14.Because in strpos() function counting starts with 0 not 1.   
Ques: 83 How to declare data types in PHP?
Ans:
Data type that we used in PHP are given below:
1.Numeric data type
2.Array data type
3.String data type
1.Numeric data type: We introduce numeric data type when we use numbers in PHP.Two different types of numeric data types are integer and double.
integer data type use to introduce the whole number.Where as double data type use to introduce float values.
Example:
$intnum = 50;
$doublepercentage = 67.9;
2.Array data type: In this we store many values in a single variable.In this we show all values of variable with their variable and index.
Example:
$arrayMarks[0] = 70;
$arrayMarks[1] = 75;
$arrayMarks[2] = 65;
$intTotalMark = $arrayMarks[0] + $arrayMarks[1] + $arrayMarks[2];
echo $intTotalMark;
Output: 210
3.String data type:In this values of variables may be of combination of characters and numbers or words.
Examle:
$stringName = "Abhi";
$stringId = "Abhi007";

String Concatenation:In thois we can add two strings using "."operator.When we add two strings second string add at the end of first string.
Example:
$stringFirst_Name = "vivek";
$stringSpace = " ";
$stringLast_Name = "agarwal";
$stringName = $stringFirst_Name.$stringSpace.$stringLast_Name;
echo $stringName;

Output: vivek agarwal
Ques: 84 What are the Limitations of Variable Naming?
Ans:
Some main limitations of Variable Naming in PHP are given below:
1.In PHP their is not a fixed limit for Variable Name as compare to other programing language.
2.First letter of PHP Variable must start with a letters,numbers or underscore "_".
3.Variable Name should be a combination of Alpha-Numeric Characters or underscores(a-z,A-Z,0-9or_)
4.Variable name must be one word.If their is more than one word in our Variable Name.Than we can distinguish them with underscore("_").Like $first_name.
Ques: 85 What are the PHP variables?
Ans:
We use Variables to store the values,Like: Strings, Numbers or Array.In PHP their s no limit to create number of variables.All variable in PHP starts with dollar("quot;)sign and we assign value to the variable using "=" operator.
Syntax:
$variable_name = vale;
Example:
<?php
$Name = "Abhi";
$Age = 23;

Ques: 86 Tell me about basic statements that we used in PHP? 
Ans:
PHP has two basic statements.These are echo and print.I have given you a example say how to use echo and print in PHP.
Example:
<html>
<title>This is my first PHP page</title>
<body>
<?php
echo "Welcome!";
?>
</body>
</html>
////
<html>
</body>
<?php
$decimal_number = 109.09;
printf("%.2f", $decimal_number);
?>
</body>
</html>
Ques: 87 What is the Syntax of PHP?
Ans:
Below I will given you how PHP work with HTML codes.Always keep that in mind PHP starts with <?php and close with ?>Their in not a specific place of this block in the HTML code.Like that,<?php/*Enter your code*/?>Now, I have given you a example on PHP. Like that you can create your first PHP file.<html><body><?phpecho \"Welcome in world of PHP.\";?></body></html> Keep one thing in mind when we write PHP code each PHP line should ends with semicolon(;).
Ques: 88 How to install PHP in our system?
Ans:
First you have download PHP software from: http://www.php.net/downloads.php
than you have to install Database Which you want to use:Like MySQL download from:
http://www.mysql.com/downloads/index.html
than download server on which you want to work.from:
http://httpd.apache.org/download.cgi
After install them you will ready to work on PHP.
Ques: 89 Why we used PHP?
Ans:
Because of several main reason we have to use PHP. These are:
1.PHP runs on many different platforms like that Unix,Linux and Windows etc.
2.It codes and software are free and easy to download.
3.It is secure because user can only aware about output doesn't know how that comes.
4.It is fast,flexible and reliable.
5.It supports many servers like: Apache,IIS etc.
Ques: 90 What do you understand about MySQL?
Ans:
MySQL is an open source Relational Database Management System(RDMS).It sound as /ma&#618;&#716;&#603;skju&#720;&#712;&#603;l/ ("My ess cue el").It is introduce in 23May,1995 by MySQLAB,its an Swedish company.Now,is a subsidiary of Sun Microsystems,.MySQL is designed in C and C++.We can download is codes as per rules of GNU(General Public Licence).
It fast,reliable and flexible.It works on many platforms like:Uinux,Linux and Windows.
Ques: 91 How PHP is more secure than JavaScript?
Ans:
We use PHP in a HTML with in some specific tags.It is much secure than JavaScript because of when client process the PHP page than PHP code only send the output of given request without PHP source code.So, the PHP code Can not steal by non-authorized person.Where in the case of JavaScript It also send the source of JavaScript to the client with output.
Ques: 92 Tell more about PHP file?
Ans:
In PHP file we may contain text, HTML tags and scripts.It returned to the browser in form of plain HTML code.We can save PHP file using these three extension .php,.php3 or .phtml. An Example of PHP file are given below:
<html>
<head><title>PHPExample</title></head>
<body>
<h1><?php echo "Welcome in PHP world"; ?></h1>
<?php
$txt = "This is my first PHP script";
/* statement */
echo $txt;
?>
</body>
</html>
Ques: 93 What is PHP?
Ans:
PHP(PHP:Hypertext Preprocessor) is a server-side programing languages.It is use to made the web pages dynamically.
PHP is introduce by Rasmus Lerdorf in 1995.It is a free released and open source softwareWe introduce PHP under the HTML tags.In this scripts are executed on server side.It supports many database like that MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.
Ques: 94 What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?
Ans:
GET Method:
Using get method we can able to pass 2K data from HTML.All data we are passing to Server will be displayed on the Browser. This is used to sent small size data.
POST Method:
1n this method we does not have any size limitation. All data passed to server will be hidden, User cannot able to see this info on the browser.The data is send into a small packets. This used to sent large amount of data.


If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

Blog Archive

 

© 2011. All Rights Reserved | Interview Questions | Template by Blogger Widgets

Home | About | Top