Home > PHP > Interview Questions on PHP

Interview Questions on PHP

Hey, I am back with some more questions on PHP. Enjoy!!

Q:- What is the difference between “GET” and “POST” methods?

Ans. Get and Post are methods used to send data to the server with the submission of the form. The default method is GET.

* The browser appends the data onto the url when GET method is used, while the data is sent as standard input when POST method is used.
* When the processing of the form has no side effects, means just for getting(retrieving) data, the GET method should be used and POST method should be used when the form processing has side effects(for example, modification of a database or subscription to a service).

Example: Suppose Sachin is filling up a form with the following information:

Name: Sachin Tendulkar

Age:35

Sex:Male

Choice:Cricket
If the form uses GET method then the location box will show the string after submitting the form like this:
http://cricketworld.com/cgi-bin/query?Name=Sachin+Tendulkar &Age=35&Sex=Male&Choice=Cricket
and if POST is used, then the location box will show:
http://cricketworld.com/cgi-bin/query

Q:- What is the difference between echo and print?

Ans. Both are the constructs to print the string on the screen. echo just outputs the contents to the screen following the construct while print returns TRUE on successful output and FALSE if it was unable to print out the string. echo can take multiple parameters while print cannot. Also echo is faster than print in execution.

Q:- What is the difference include() and require()?
Ans. Both the functions are used to include and evaluate the specific file, but the only difference is require() produces FATAL ERROR and stops the execution if the specified file is not found while include() produces a warning message only and proceeds the execution.

Q:- What is meant by nl2br()?

Ans. This function inserts HTML line breaks before all newlines in a string

example: <?php
echo nl2br(“I am not getting\n what you are saying”);
?>
Output: I am not getting<br />
what you are saying

Q:- What is the differen between strstr() and stristr() functions?

Ans. strstr() function is used to return the sub string from first occurrence of string point from the string base.If string point is not found, returns FALSE. syntax: strstr(string base,string point)
examle: <?php
$email = ‘mayank@gmail.com’;
$domain = strstr($email, ‘@’);
echo $domain;
?>
output: @gmail.com
stristr() does the same thing in Case-insensitive manner.

Who will come with smart comments? Let’s see.

Advertisements
Categories: PHP
  1. June 23, 2006 at 9:33 am

    Nice Blog. These are very good questions and answers for interview.

    Thanks

  2. Ravi
    June 23, 2006 at 11:36 am

    Thanks 🙂
    gr8 work Asit

    N’Joy Life till not Wife
    rAVI

  3. mini
    July 13, 2006 at 6:25 am

    I didn’t get properly what’s the use of nl2br() ?
    Will you explain it more?

  4. July 13, 2006 at 6:59 am

    Sure, I like your approach. I will come with some more examles on nl2br().
    Thanks!!

  5. P.A.Patel
    August 28, 2006 at 8:25 am

    These are very good questions and answers for interview.please give me more interview questions and their answers plz.

  6. August 28, 2006 at 9:25 am

    Thanks for your response. I will try to get back with some more stuff.

  7. Amul
    September 7, 2006 at 2:04 pm

    Hi,

    Its great to collect such quetions and answering them.

    Can u give me the difference of sessions and cookies in PHP

    Thanking you

    regards
    amul

  8. sureshkumar
    November 17, 2007 at 12:28 pm

    hi
    Thanks for you

  9. November 20, 2007 at 5:36 am

    Hi Check my online profile from here-

    http://mayanksrivastava.cv.googlepages.com

  10. Priya
    August 20, 2008 at 7:50 am

    Thanks? Shall i get more inte ques from u Asit..

  11. dilip
    September 18, 2008 at 11:50 am

    i want code for resume uploading with out creating database,so plzz forward code to my email

    thanks&regards
    dilip

  12. James Bower
    September 7, 2009 at 9:16 pm

    Great blog, reading it through RSS feed as well

  13. December 27, 2009 at 2:04 am

    Simply want to say your article is stunning. The knowledge in your post is simply impressive and i can take for granted you are an expert on this subject. Well with your permission allow me to grab your rss feed to keep up to date with future post. Thanks a million and please keep up the fabulous work.

  14. June 2, 2011 at 6:20 am

    I love it, I would love for you to be a guest writer on my blog sometime, let me know.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: