Php interview questions for beginers

These are the some php interview questions from www.w3answers.com have answered for some questions

  1. What are the differences between Get and post methods in form submitting, give the case where we can use get and we can use post methods?

get is like query string all the variables will be displayed in he url
where as post is the standard way of sending th evariables
When we submit a form, which has the GET method it displays pair of name/value used in the form at the address bar of the browser preceded by url. Post method doesn’t display these values.

  1. Who is the father of PHP and explain the changes in PHP versions?
    Father of php is Rasmus Lerdorf

  2. How can we submit a form without a submit button?
    Ans : I can submit a form in many ways, for e.g.

  3. When user click on checkbox, or drop down

  4. When user click on radio button

  5. At the end of the form I will type “Click here
    to submit” & link text to the processing file
    form.submit();

  6. In how many ways we can retrieve the date in the result set of mysql using PHP?

  7. What is the difference between mysql_fetch_object and mysql_fetch_array?

mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
mysql_fetch_object is like fetching value from a recordset
and mysql_fetch_array is gettin array’s value

  1. What is the difference between $message and $$message?
    $message is variable whereas $$message is Dynamic variable.
    eg.

$user=”bob”
is equivalent to
$holder=”user”;
$$holder=”bob”;

  1. How can we extract string ‘abc.com ‘ from a string ‘http://info@abc.com’ using regular expression of PHP?
    $exploded[1] should have abc.com
    Use the function split split(“@”,”http://info@abc.com”) which returns an array any second element of the returned array will hold the value as abc.com.
    echo substr(”http://info@abc.com”,12,19);

  2. How can we create a database using PHP and mysql?
    mysql_create_db() should work

  3. What are the differences between require and include, include_once?

require_once(),include_once() both the functions include and evalute the specified file only once
and if the specified file is opened previous to the present call occurrance, it will not be done again.
But require() and include() will do it as many times they are asked to do.
The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. The major difference between include() and require() is that in failure include produces a warning message whereas require produces a Fatal errors.

  1. Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?
    Yes we can include that many times we want, but here are some things to make sure of:
    (including abc.PHP, the file names are case-sensitive)
    there shouldnt be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

  2. What are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee(eno int(2),ename varchar(10)) ?
    Table Types are
    • ISAM(Index Sequential Access Method)
    • MyISAM
    o Static
    o Dynamic
    o Compress
    • Merge
    • Heap (Fastest tables because it stores in to the RAM)
    • BDB
    • InnoDB (Transaction safe table)
    When you fire the above create query MySQL will create the Dynamic table.

  3. Functions in IMAP, POP3 AND LDAP?

  4. How can I execute a PHP script using command line?
    Through php parse you can execute PHP script using command line. By default location of php parser is /var/www/html so set the path of this directory and just use as following
    PHP sample.php

  5. Suppose your Zend engine supports the mode <? ?> Then how can u configure your PHP Zend engine to support <?PHP ?> mode ?
    In php.ini file:
    set
    short_open_tag=on
    to make PHP support

  6. Shopping cart online validation i.e. how can we configure Paypal, etc.?

  7. What is meant by nl2br()?
    nl2br() inserts html in string. echo nl2br(”god bless
    you”);
    output
    god bless
    you

  8. Draw the architecture of Zend engine?

  9. What are the current versions of apache, PHP, and mysql?

  10. What are the reasons for selecting lamp (linux, apache, mysql, PHP) instead of combination of other software programmes, servers and operating systems?

  11. How can we encrypt and decrypt a data present in a mysql table using mysql?

  12. How can we encrypt the username and password using PHP?
    You can encrypt a password with the following
    Mysql>SET PASSWORD=PASSWORD(“Password”);

  13. What are the features and advantages of object-oriented programming?

  14. What are the differences between procedure-oriented languages and object-oriented languages?

  15. What is the use of friend function?

  16. What are the differences between public, private, protected, static, transient, final and volatile?

  17. What are the different types of errors in PHP?
    Three are three types of errors 1) Fatal errors 2) Parser errors 3) Startup errors.

  18. What is the functionality of the function strstr and stristr?
    string strstr ( string str1, string str2) this function search the string str1 for the first occurrence of the string str2 and returns the part of the string str1 from the first occurrence of the string str2. This function is case-sensitive and for case-insensitive search use stristr() function.

  19. What are the differences between PHP 3 and PHP 4 and PHP 5?

  20. How can we convert asp pages to PHP pages?

  21. What is the functionality of the function htmlentities?

  22. How can we get second of the current time using date function?

  23. How can we convert the time zones using PHP?

  24. What is meant by urlencode and urldocode?
    string urlencode(str)
    where str contains a string like this “hello world” and the return value will be URL encoded and can be use to append with URLs, normaly used to appned data for GET like someurl.com?var=hello%world
    string urldocode(str)
    this will simple decode the GET variable’s value
    Like it echo (urldecode($_GET_VARS[var])) will o/p “Hello world”

  25. What is the difference between the functions unlink and unset?

  26. How can we register the variables into a session?

  27. How can we get the properties (size, type, width, height) of an image using PHP image functions?

  28. How can we get the browser properties using PHP?

  29. What is the maximum size of a file that can be uploaded using PHP and how can we change this?

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

  31. How can we take a backup of a mysql table and how can we restore it. ?

  32. How can we optimize or increase the speed of a mysql select query?

  33. How many ways can we get the value of current session id?

  34. How can we destroy the session, how can we unset the variable of a session?

  35. How can we destroy the cookie?

  36. How many ways we can pass the variable through the navigation between the pages?

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

  38. What are the different functions in sorting an array?

  39. How can we know the count/number of elements of an array?

  40. What is the PHP predefined variable that tells the What types of images that PHP supports?

  41. How can I know that a variable is a number or not using a JavaScript?

  42. List out some tools through which we can draw E-R diagrams for mysql.

  43. How can I retrieve values from one database server and store them in other database server using PHP?

  44. List out the predefined classes in PHP?
    Predefined Classes

  45. Standard Defined Classes
    These classes are defined in the standard set of functions included in the PHP build.
    a. Directory
    The class from which dir() is instantiated.
    b.stdClass
    2.Ming Defined Classes
    These classes are defined in the Ming extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.
    a.swfshape b. swffill c. swfgradient d. swfbitmap e. swftext f. swftextfield
    g. swffont h. swfdisplayitem i. swfmovie j. swfbutton k. swfaction
    l. swfmorph m. swfsprite

  46. Oracle 8 Defined Classes
    These classes are defined in the Oracle 8 extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.
    a. OCI-Lob b. OCI-Collection

  47. qtdom Defined Classes
    These classes are defined in the qtdom extension, and will only be available when that extension has either been compiled into PHP or dynamically loaded at runtime.
    a. QDomDocument b. QDomNode

  48. How can I make a script that can be bilanguage (supports English, German)?

  49. What are the difference between abstract class and interface?

  50. How can we send mail using JavaScript?
    The answer for this question
    function myfunction(form)
    {
    tdata=document.myform.tbox1.value;
    location=”mailto:dep7abc@leeds.ac.uk?subject=”+tdata+”/MYFORM”;
    return true;
    }
    This question is wrong. You aren’t really ’sending mail’ when doing a ‘mailto’ and so it’s a misleading question… A smart candidate would just say “It’s not possible” and you may write him off.

The answers aren’t brilliant I’m afraid. You’ve missed the mark on a few of them. Just some comments:

  1. The key difference between GET and POST is that POST has side-effects, and thus browsers will present a confirmation dialog to the user on refresh or “back”.

  2. I suspect the key point is “using javascript”

  3. The question specifically says “using a regular expression”, but you use other functions.

  4. More specifically nl2br converts newlines to html br tags

  5. Technically, this is using mysql not PHP. PHP has an md5 function that would normally suffice. Also, since the password function in mysql can change between versions, using mysql’s md5 function would be better here. As an aside, concatonating the record id (or something else handy) before hashing will stop different users with the same password getting the same hash.

  6. There are more than 3: see http://uk.php.net/manual/en/ref.errorfunc.php#errorfunc.constants for a full list.

Thanks for ur reply.

But still there are questions which is unanswered :shifty:

using mysql’s md5 function would be better here.

Did you mean that, or did you mean using PHP’s md5() function would be better? (If using the PHP function then the MySQL version would not affect a PHP script).

Did you mean that, or did you mean using PHP’s md5() function would be better? (If using the PHP function then the MySQL version would not affect a PHP script).

What I meant was that using mysql’s md5() function would be better than using mysql’s password() function. Using PHP’s md5() function would be even better, which is what my first statement meant. I probably should have worded it differently - hope this clarifies what I meant.

are you implying that you want us to give you answers to all of those unanswered questions?

i can tell you right now, if you cannot answer those questions, even with the ability to use the manual as an open book, you probably arent going to last very long at that job. although, maybe you are just curious.

Hah very nice although some of the answers aren’t too strong or fall back to using tertiary skills (which would be expected for any entry/junior level PHP developer) like JavaScript and generic SQL.

Having recently taken part in a couple of interviews, I’d more be looking for general development skills rather than somebody’s specific knowledge of a language (say 50/50 for a good entry-level candidate, going upto 70/30 or so for a more experienced position).

Anyway a couple of interesting questions are:

Q: Describe the process from a users web browser, to the web-server and back again.

Q: How would you check that a string is a palindrome?
hint using only one statement.

Q: What’s the maximum size of intergal numbers in PHP? How would you manipulate very large numbers? (e.g. 8+ billion)

Q: What is ‘htmlentities’ and it’s relationship with preventing XSS attacks/vulnerabilities?

Q: Describe the differencesbetween the object models in PHP 4 and PHP 5.

Oh and on a side note, if you can get through them easily and are looking for development work in London, UK - give me a PM for more details.

Now this one got me thinking…there isn’t a string reverse method in PHP as far as I know (and if there is then I feel like an idiot). With one line I’d try to solve it with something like

if $test = join( array_reverse(explode($test)) );

Is there a better way? Also, do I get the job :smiley:

Very interesting:


$string = "poop"; # longest one I know

echo (strtolower($string) == implode('', array_reverse(str_split(strtolower($string), 1)))) ? "yes" : "no";

Also it seems silly to expect someone to know what the max value of an INT is off the top of their head, particular PHP.

I know its 2.1 something billion for signed, and doubled for unsigned but I wouldn’t know unless I googled it to know exactly.



$word = 'racecar';
echo ($word == strrev($word)) ? 'TRUE' : 'FALSE';


Didn’t know there was a strrev function. Good to know!

Very useful test.

Thanks!

Hey thanks a lot for sharing useful interview questions… which will be very helpful while attending the interviews…
glad i found ur site…really a very helpful site…
by the way check out my collection of php interview questions from here:php interview questions

Hi,

Thanks very much for this comment. It help me to think about my ideals.

Tks again and pls keep posting.

[QUOTE=anbetophillip;]Hi,

Thanks very much for this comment. It help me to think about my ideals.

Tks again and pls keep posting.[/QUOTE]

Apart from that, this link below may be useful: Interview questions and answers

I love these questions. Whoever thought them up for interviewing people with should be fired.

If a (potential) programmer doesn’t know how to count() the elements in an array (q. 48), how on earth can you expect them to draw the architecture of the Zend engine (q. 17)? There are huge discrepancies in the levels of the questions.

Unless of course they expect an answer like:

Input -> Zend Engine -> Output -> Profit!

:smiley: