100 PHP interview questions and answers


PHP interview questions and answers

PHP interview questions and answers - post on Aug 24, 2013

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.

Part 1   Part 2   Part 3   Part 4   Part 5   Part 6
Download PHP interview questions and answers
What is PHP?

Latest Answer - PHP (Hyper text Pre Processor) is a scripting language commonly used for web applications.............
Read answer

What Is a Session in PHP?

Latest Answer - A PHP session is no different from a normal session. It can be used to store information on the server for future use.............
Read answer

Explain the difference between $message and $$message?

Latest Answer - $message is used to store variable data. $$message can be used to store variable of a variable.............
Read answer

How to set cookies in PHP?

Latest Answer - Cookies are often used to track user information.............
Read answer

What is the difference between include and require?

Latest Answer - Require () and include () are the same with respect to handling failures.............
Read answer

What is urlencode and urldecode?

Latest Answer - Urlencode can be used to encode a string that can be used in a url.............
Read answer

What are the different types of errors in PHP?

Latest Answer - Different types of errors are............
Read answer

Explain how to submit form without a submit button.

Latest Answer - A form data can be posted or submitted without the button in the following ways:............
Read answer

What are the functions for IMAP?

Latest Answer - IMAP is used for communicate with mail servers. It has a number of functions.............
Read answer

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

Latest Answer - Default time allowed for the PHP scripts to execute is 30s defined in the php.ini file.............
Read answer

What is Type juggle in php?

Latest Answer - Type Juggling means dealing with a variable type. In PHP a variables type............
Read answer

What is the difference between mysql_fetch_object and mysql_fetch_array?

Latest Answer - Mysql_fetch_object returns the result from the database as objects while............
Read answer

What is the difference between the functions unlink and unset?

Latest Answer - Unlink is a function for file system handling which deletes a file.............
Read answer

What is Joomla in PHP?

Latest Answer - Joomla is an open source content management system.............
Read answer

What is zend engine?

Latest Answer - Zend Engine is used internally by PHP as a complier and runtime engine.............
Read answer

What is the difference between Split and Explode?

Latest Answer - Both the functions are used to Split a string. However, Split is used to split............
Read answer

What is the difference between echo and print statement?

Latest Answer - Echo can accept multiple expressions while print cannot.............
Read answer

What is CAPTCHA?

Latest Answer - CAPTCHA is a test to determine if the user using the system............
Read answer

What is difference between developing website using Java and PHP?

Latest Answer - In order to make interactive pages, java uses JSP (Java Server
Read answer

How do you create sub domains using PHP?

Latest Answer - Wild card domains can be used. Sub domains can be created by first creating............
Read answer

How to upload files using PHP?

Latest Answer - Files can be uploaded in PHP by using the tag type=”file”.............
Read answer< /A>

What is the difference between Notify URL and Return URL?

Latest Answer - Notify URL and Return URL is used in Paypal Payment Gateway integration.............
Read answer

Describe functions STRSTR() and STRISTR.

Latest Answer - Both the functions are used to find the first occurrence of a string.............
Read answer

What are the various methods to pass data from one web page to another web page?

Latest Answer - Different methods to pass data from one web page to another:............
Read answer  

Test your PHP skills - PHP (39 questions)
Test your MySQL skills - MySQL (20 questions) 

Test your PHP knowledge with our multiple choice questions!

Explain how to execute a PHP script using command line.
How can we increase the execution time of a PHP script?
Explain the purpose of output buffering in PHP.
Describe session in PHP.
How can we know the number of days between two given dates using PHP?

PHP Interview - Jan 22, 2009 at 18:00 pm by Rajmeet Ghai

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.

Describe session in PHP.

When a user logs in an application, his details are usually stored in a session variable. This information is available to all pages in one application. Sessions in PHP work using a unique id for each visitor.

How can we know the number of days between two given dates using PHP?

The start date and end date can be first found as shown below:

$date1= strotime($start_date);
$date2= strotime($end_date);
$date_diff = (($date1)- ($date2)) / (60*60*24)

Write your comment - Share Knowledge and Experience

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 01:31 AM


session are used to store information on future used

puneet tiwari 09-9-2014 05:49 AM



abc 04-30-2014 02:02 AM


very nice

abc 04-30-2014 02:00 AM

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 05:02 AM

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 = "http://domain.com/submit.php?disc=".urlencode($discount);

echo $url;

Output: "http://domain.com/submit.php?disc=10%2E00%25".

Rohit Sharma 12-11-2011 04:58 AM

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 04:55 AM

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 04:53 AM

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 04:47 AM

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 05:48 AM

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 05:47 AM

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 05:45 AM


Related Links

Related Books

Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us