PHP Interview Questions-Answers Part-II

Questions : 26 What are the different types of errors in PHP?
Answer : 26 Three are three types of errors:
1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script for example, accessing a variable that has not yet been defined. By default,
such errors are not displayed to the user at all although, as you will see, you can change this default behavior.
2. Warnings: These are more serious errors for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors for example, instantiating an object of a non-existent class, or calling a
non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.

Questions : 27 What is the functionality of the function strstr and stristr?
Answers : 27 strstr Returns part of string from the first occurrence of needle(sub string that we finding out ) to the end of string.
$email= ‘';
$domain = strstr($email, ‘@’);
echo $domain; // prints
here @ is the needle
stristr is case-insensitive means able not able to differentiate between a and A

Questions : 28 What are the differences between PHP 3 and PHP 4 and PHP 5?
Answer : 28 There are lot of difference among these three version of php
1>Php3 is oldest version after that php4 came and current version is php5 (php5.3) where php6 have to come
2>Difference mean oldest version have less functionality as compare to new one like php5 have all OOPs concept now where as php3 was pure procedural language constructive like C
In PHP5 1. Implementation of exceptions and exception handling
2. Type hinting which allows you to force the type of a specific argument
3. Overloading of methods through the __call function
4. Full constructors and destructors etc through a __constuctor and __destructor function
5. __autoload function for dynamically including certain include files depending on the class you are trying to create.
6 Finality : can now use the final keyword to indicate that a method cannot be overridden by a child. You can also declare an entire class as final which prevents it from having any children at all.
7 Interfaces & Abstract Classes
8 Passed by Reference :
9 An __clone method if you really want to duplicate an object
10 Numbers of Functions Deprecated in php 5.x like ereg,ereg_replace,magic_quotes_runtime, session_register,register_globals, split(), call_user_method() etc

Questions : 29 How can we convert asp pages to PHP pages?
Answer : 29 There are lots of tools available for asp to PHP conversion. you can search Google for that. the best one is available at

Questions : 30 What is the functionality of the function htmlentities?
Answer : 30 Convert all applicable characters to HTML entities
This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.

Questions : 31 How can we get second of the current time using date function?
Answer : 31 $second = date(“s”);

Questions : 32 How can we convert the time zones using PHP?
Answer : 32 By using date_default_timezone_get and date_default_timezone_set function on PHP 5.1.0

<?php // Discover what 8am in Tokyo relates to on the East Coast of the US
// Set the default timezone to Tokyo time:

// Now generate the timestamp for that particular timezone, on Jan 1st, 2000
$stamp = mktime(8, 0, 0, 1, 1, 2000);

// Now set the timezone back to US/Eastern

// Output the date in a standard format (RFC1123), this will print:
// Fri, 31 Dec 1999 18:00:00 EST
echo '', date(DATE_RFC1123, $stamp) ,'';?>

Questions : 33 What is meant by urlencode and urldocode?
Answer : 33 URLencode returns a string in which all non-alphanumeric characters
except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+)
signs. It is encoded the same way that the posted data from a WWW form is encoded, that is the same way as in
application/x-www-form-urlencoded media type.

urldecode decodes any %## encoding in the given string.

Questions : 34 What is the difference between the functions unlink and unset?
Answer : 34 unlink() deletes the given file from the file system.
unset() makes a variable undefined.

Questions : 35 How can we register the variables into a session?
Answer : 35 $_SESSION[‘name’] = “sonia”;

Questions : 36 How can we get the properties (size, type, width, height) of an image using PHP image functions?
Answer : 36 To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function t

Questions : 37 How can we get the browser properties using PHP?
Answer : 37 By using

Questions : 38 What is the maximum size of a file that can be uploaded using PHP and how can we change this?
Answer : 38 By default the maximum size is 2MB. and we can change the following
setup at php.ini upload_max_filesize = 2M

Questions : 39 How can we increase the execution time of a PHP script?
Answer : 39 by changing the following setup at php.inimax_execution_time = 30; Maximum execution time of each script, in seconds

Questions : 40 How can we take a backup of a MySQL table and how can we restore it. ?
Answer : 40 To backup: BACKUP TABLE tbl_name[,tbl_name] TO
RESTORE TABLE tbl_name[,tbl_name] FROM ‘/path/to/backup/directory’mysqldump: Dumping Table Structure and DataUtility to dump a database or a collection of database for backup or for transferring the data to another SQL server (not necessarily a MySQL server). The dump will contain SQL statements to create the table and/or populate the table.
-t, no-create-info
Don’t write table creation information (the CREATE TABLE statement).
-d, no-data
Don’t write any row information for the table. This is very useful if
you just want to get a dump of the structure for a table!

Questions : 41 How can we optimize or increase the speed of a MySQL select query?
Answer : 41 first of all instead of using select * from table1, use select
column1, column2, column3.. from table1
Look for the opportunity to introduce index in the table you are querying.
use limit keyword if you are looking for any specific number of
rows from the result set.

Questions : 42 How many ways can we get the value of current session id?
Answer : 42 session_id() returns the session id for the current session.

Questions : 43 How can we destroy the session, how can we unset the variable of a session?
Answer : 43 session_unregister — Unregister a global variable from the current session
session_unset Free all session variables

Questions : 44 How can we set and destroy the cookie n php?
Answer : 44 By using setcookie(name, value, expire, path, domain); function we can set the cookie in php ;
Set the cookies in past for destroy. like
setcookie(“user”, “sonia”, time()+3600); for set the cookie
setcookie(“user”, “”, time()-3600); for destroy or delete the cookies;

Questions : 45 How many ways we can pass the variable through the navigation between the pages?
Answer : 45


Questions : 46 What is the difference between ereg_replace() and eregi_replace()?
Answer : 46 eregi_replace() function is identical to ereg_replace() except that
this ignores case distinction when matching alphabetic
characters.eregi_replace() function is identical to ereg_replace()
except that this ignores case distinction when matching alphabetic

Questions : 47 What are the different functions in sorting an array?
Answer : 47 Sort(), arsort(),
asort(), ksort(),
natsort(), natcasesort(),
rsort(), usort(),
array_multisort(), and

Questions : 48 How can we know the count/number of elements of an array?
Answer : 48 2 ways
a) sizeof($urarray) This function is an alias of count()
b) count($urarray)

Questions : 49 what is session_set_save_handler in PHP?
Answer : 49 session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.

Questions : 50 How can I know that a variable is a number or not using a JavaScript?
Answer : 50 bool is_numeric ( mixed var)
Returns TRUE if var is a number or a numeric string, FALSE otherwise.or use isNaN(mixed var)The isNaN() function is used to check if a value is not a number.

Part-III coming soon…….

Leave a Reply

You must be logged in to post a comment.