PHP Interview Questions and Answers - Test & Download!

What is PHP?

PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for web development. PHP scripts are executed on the server. PHP allows writing dynamically generated web pages efficiently and quickly. The syntax is mostly borrowed from C, Java and perl. PHP is free to download and use.

What is PEAR in php?

PEAR(PHP Extension and Application Repository) is a framework and repository for reusable PHP components. PEAR is a code repository containing all kinds of php code snippets and libraries.

PEAR also offers a command-line interface that can be used to automatically install "packages".

Explain how to submit form without a submit button.

We can achieve the above task by using JavaScript code linked to an event trigger of any form field and call the document.form.submit() function in JavaScript code.

Echo vs. print statement.

echo() and print() are language constructs in PHP, both are used to output strings. The speed of both statements is almost the same.

echo() can take multiple expressions whereas print cannot take multiple expressions.

Print return true or false based on success or failure whereas echo doesn't return true or false.

$message vs. $$message in PHP.

$message is a variable with a fixed name. $$message is a variable whose name is stored in $message.

If $message contains "var", $$message is the same as $var.

Explain the different types of errors in PHP.

Notices, Warnings and Fatal errors are the types of errors in PHP


Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.


Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.

Fatal errors:

Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.

Explain the importance of the function htmlentities.

The htmlentities() function converts characters to HTML entities.

What is MIME?

MIME - Multi-purpose Internet Mail Extensions.

MIME types represents a standard way of classifying file types over Internet.

Web servers and browsers have a list of MIME types, which facilitates files transfer of the same type in the same way, irrespective of operating system they are working in.

A MIME type has two parts: a type and a subtype. They are separated by a slash (/).

MIME type for Microsoft Word files is application and the subtype is msword, i.e. application/msword.

Explain how to execute a PHP script using command line.

PHP script using command line can be executed using SAPI (Server Application programming Interface). Using SAPI Command Line Interface the PHP code can be passed to execute directly

Php –r ‘print_r(get_defined_constanrs());’

From a shell, php –v will display whether the SAPI is CLI or CGI

How can we increase the execution time of a PHP script?

By default the PHP script takes 30secs to execute. This time is set in the php.ini file. This time can be increased by modifying the max_execution_time in seconds. The time must be changed keeping the environment of the server. This is because modifying the execution time will affect all the sites hosted by the server.

Explain the purpose of output buffering in PHP.

Output buffering in PHP buffers a scripts output. This buffer can be edited before returning it to the client. Without output buffering, PHP sends data to the web server as soon as it is ready. Output buffering "send" cookies at any point in the script. Cookies do not have to be necessarily sent near the start of page. Output buffers are stackable and hence sending to output is by choice.
1 2 3 4 5

PHP - What is PHP?
PHP - PHP (Hyper text Pre Processor) is a scripting language commonly used for web applications.....
PHP Session - What Is a Session in PHP?
PHP Session - A PHP session is no different from a normal session. It can be used to store information on the server for future use....
PHP message - Explain the difference between $message and $$message?
PHP message - $message is used to store variable data. $$message can be used to store variable of a variable......
Post your comment
Discussion Board
help me to get following accurate answer

define ("ab" ,10);
define("cd" ,1);
define("ef2" ,2);
define("gh3" ,3);

echo 'ab' . "
echo constant ( 'ab' );

echo 'cd' . "
echo constant ('cd');

echo 'ef2' ."
echo constant ("ef2");

echo 'gh3' ."
echo constant ("gh3");

Manjunath 06-2-2015
session are used to store information on future used
puneet tiwari 09-9-2014
abc 04-30-2014
very nice
abc 04-30-2014
PHP interview questions and answers
How can I execute a PHP script using command line?

You can execute a PHP script by running the Command line interface program, in which you can enter the PHP script file as an argument. If the file is made for the web interface then it may not execute properly using command line. Command line allows faster execution of the statements and gives faster results.

How can we encrypt the password using PHP?

crypt() function is used to create one way encryption. It takes one input string and one optional parameter. The function look is defined as: crypt (input_string, salt), where input_string consists of the string which has to be encrypted and salt is an optional parameter. PHP uses DES for encryption. The format is as follows:-


$password = crypt('mypassword');

print $password . “ is the encrypted version of mypassword”;


What are different types of Runtime Errors in PHP?

There are three types of Runtime Errors in PHP. They are as follows:-

- Notices: These are trivial, non-critical errors eg: undefined variable
- Warnings: These are serious errors eg. Including non-existing file
- Fatal errors: These are critical errors eg. Calling of non-existent function.
Rohit Sharma 12-11-2011
PHP interview questions and answers
What does a special set of tags do in PHP?

Special set of tags allows you to display the output directly to the browser. The special set of tags are represented as <?php..(your statements)..?>. They allow you to write your code for execution and representation, that you want to display and execute. The example is as follows to explain it more:


<?php echo "Hello world"; ?> // it will print the Hello world directly to browser


Define urlencode() and urldecode() used in PHP?

urlencode() returns the URL encoded version of given string. For URL encoding string values are used in the queries to be passed as URL. Whereas,

urldecode() returns the URL decoded string (original string) which will be decoded by taking the already encoded string.

Example is as follows:

$discount ="10.00%";

$url = "".urlencode($discount);

echo $url;

Output: "".
Rohit Sharma 12-11-2011
PHP interview questions and answers
What is the difference between $message and $$message?

The only difference between $message and $$message is that, $message is a normal variable and $$message is variable to variable. The difference in functioning is shown below:

When declaring a variable in PHP the variable gets declared like this

$message //which is simply a variable

To store the data to assign the value to it we write like

$message= “ride”; //assigned the string to the variable

echo $message; // it will print the value

Whereas if you want to display the variable to variable then you use



echo $message; //print var

echo $$message; //print Hello.

What Is a Persistent Cookie?

Persistent cookie is a cookie which is permanently stored on user’s computer in a cookie file. They are used for tracking the user information of the users who are browsing from a very long time. They also have the drawbacks of being unsecure, as user can see the cookies which are saved on the computer.
Rohit Sharma 12-11-2011
PHP interview questions and answers
What is a PHP Session?

PHP session allows you to store the user session, like their information on server for faster access and for later use like username, IP addresses, their actions etc. The information which is saved is temporary and can be deleted after the user is no longer active. Example of starting a PHP session is as follows:

session_start(); // start up your PHP session!

What is meant by PEAR in php? What is the purpose of it?

PEAR stands for "PHP Extension and Application Repository". As the name suggests, it gives advanced functionality to the PHP language and include many applications which can be used on fly. The purpose of it is as follows:-

- Open source structured library for PHP users
- Code distribution and package maintenance system
- Standard style for code written in PHP
Rohit Sharma 12-11-2011
PHP interview questions and answers.
Is PHP a loosely Typed Language? What is the difference between strongly typed and loosely typed language?

Yes, PHP is a loosely typed language. In this type of language variable doesn’t need to be declared before their use. This language converts the data according to its given value. Whereas, in strongly typed language first every type has to be declared (defined) then only it can be used.
Rohit Sharma 12-11-2011
Php interview questions and answers
What do you mean by PEAR in PHP?
PEAR is a framework and distribution system for reusable PHP components.

What do you mean by Persistent Cookie?
A cookie which is stored in a cookie file permanently on the browser’s computer.

Differentiate between DROP a table and TRUNCATE a table.
DROP - It will delete the table and table data.
TRUNCATE - It will delete data of the table but not the table definition.

List the different run time errors in PHP.

a. Notices
b. Warnings
c. Fatal errors
Arpita 12-5-2011
Php interview questions and answers
Explain "GET" and "POST" methods.

Both the methods are used to send data to the server.
GET method - the browser appends the data onto the URL.
Post method - the data is sent as “standard input.”

Explain the "unlink" and "unset" functions.

unlink() function is for file system handling. It just deletes the file in context.
unset() function is for variable management. It makes a variable undefined

How will you change the name of a column in a table?
ALTER TABLE table_name CHANGE old_colm_name new_colm_name
Shashank 12-5-2011
Php interview questions and answers
What is the default session time in PHP?
Until closing the browser.

How will you create a database using PHP and MySQL?
By using : mysql_create_db("Database Name")

How will you find out the value of current session id?
By using: session_id()
Astha 12-5-2011