Home Other Languages PHP Interview Questions PHP Interview Questions - 2

Login Form




PHP Interview Questions - 2 Print E-mail

1. How do you call a constructor for a parent class?

parent::constructor($value)

 

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

Simple arithmetic:

$date1 = date('Y-m-d');
$date2 = '2006-07-01';
$days = (strtotime() - strtotime()) / (60 * 60 * 24);
echo "Number of days since '2006-07-01': $days";

 

3. How To Get the Uploaded File Information in the Receiving Script?

Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:

$_FILES[$fieldName]['name'] - The Original file name on the browser system.

$_FILES[$fieldName]['type'] - The file type determined by the browser.

$_FILES[$fieldName]['size'] - The Number of bytes of the file content.

$_FILES[$fieldName]['tmp_name'] - The temporary filename of the file in which the uploaded file was stored on the server.

$_FILES[$fieldName]['error'] - The error code associated with this file upload.

The $fieldName is the name used in the <INPUT TYPE=FILE, NAME=fieldName>

 

4. How do you define a constant?

Via define() directive, like define ("MYCONSTANT", 100);

 

5. How can we send mail using JavaScript?

No. There is no way to send emails directly using JavaScript.

But you can use JavaScript to execute a client side email program send the email using the "mailto" code. Here is an example:

function myfunction(form)
{
tdata=document.myform.tbox1.value;
location="mailto: This e-mail address is being protected from spambots. You need JavaScript enabled to view it ?subject=...";
return true;
}

 

6. How can we submit a form without a submit button?

If you don't want to use the Submit button to submit a form, you can use normal hyper links to submit a form. But you need to use some JavaScript code in the URL of the link. For example:

<a href="javascript: document.myform.submit();">Submit Me</a> 

 

7. Would you initialize your strings with single quotes or double quotes?

Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

 

8. What Is a Session?

A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.

There is only one session object available to your PHP scripts at any time. Data saved to the session by a script can be retrieved by the same script or another script when requested from the same visitor.

Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

 

9. What is the purpose of the following files having extensions: frm, myd, and myi? What these files contain?

In MySQL, the default table type is MyISAM.
Each MyISAM table is stored on disk in three files. The files have names that begin with the table name and have an extension to indicate the file type.

The '.frm' file stores the table definition.
The data file has a '.MYD' (MYData) extension.
The index file has a '.MYI' (MYIndex) extension,

 

10. What is the difference between ereg_replace() and eregi_replace()?

eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.