PHP Interview Question and Answer for Freshers

Question1 : How to use of header() functions in php?

Answer:

1. redirect from current page to another:

2. To send HTTP status code

3. To send Send a raw HTTP header

 

Question2: Types of inheritance supported by PHP?

Answer: There are following type of inheritance
Single Inheritance – Support by PHP
Multiple Inheritance – Not support
Hierarchical Inheritance – Support by PHP
Multilevel Inheritance – Support by PHP

 

Question3: Difference between the functions unlink and unset?

Answer:  unlink is used to remove the file from server and unset is used to remove the variable.

 

Question4: What are default session time and path?

Answer:  Default Session Time: 1440 seconds     AND   Default Session Path: /tmp folder in server.

 

Question 5: How to add 10 mins to a date?

Answer:

 

Question6: What is PEAR?
Answer: PEAR ( PHP Extension and Application Repository)  is a framework and repository for reusable PHP components. It is used to install the application package.

 

Question 7: How to get Path From URL in php?

Answer:

 

Question8: What is the use of  MIME?
Answer: Full form of MIME is “Multi-purpose Internet Mail Extensions”.
It is extension of e-mail protocol helps to exchanges the different kids of data files (like audio, video, images, application programs and ASCII etc) over the internet.

 

Question9: what is the use of session_set_save_handler() in php?

Answer:  session_set_save_handler() is used to save the session data into database.

There are the use of 6 callback functions which call automatically:

openFunction will be called automatically when session start.
closeFunction will be called automatically when session end.
readFunction will be called automatically when you read the session.
writeFunction will be called automatically when you write in the session.
destroyFunction will be called automatically when you destroy in the session.
gcFunction will be called automatically when session inactive for long time.

 

Question10: Why we use  nl2br?
Answer: we used nl2br to insert the line break.

Question11: How to extract seconds, minutes and hour from date?

Answer:

 

Question12: How to convert object data to array?

Answer:

 

Question13: How to create a folder if it doesn’t already exist?
Answer:
file_exists() is used to check directory exist OR NOT.
mkdir() is used to create the new directory.