PHP inteview questions and answers
Page 1 Page 2 Page 3 Page 4 Page 5

 
Bakken in 1999 and quite a lot of people have joined the project since then.

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";

How can we repair a MySQL table?
The syntex for repairing a mysql table is:

REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED

This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.

What is the difference between $message and $$message?
Anwser 1:
$message is a simple variable whereas $$message is a reference variable. Example:
$user = 'bob'

is equivalent to

$holder = 'user';
$$holder = 'bob';


Anwser 2:
They are both variables. But $message is a variable with a fixed name. $$message is a variable who's name is stored in $message. For example, if $message contains "var", $$message is the same as $var.

What Is a Persistent Cookie?
A persistent cookie is a cookie which is stored in a cookie file permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
·    Temporary cookies can not be used for tracking long-term information.


·    Persistent cookies can be used for tracking long-term information.
·    Temporary cookies are safer because no programs other than the browser can access them.
·    
·    Persistent cookies are less secure because users can open cookie files see the cookie values.

What does a special set of tags <?= and ?> do in PHP?
The output is displayed directly to the browser.


How do you define a constant?
Via define() directive, like define ("MYCONSTANT", 100);
How To Write the FORM Tag Correctly for Uploading Files?
When users clicks the submit button, files specified in the <INPUT TYPE=FILE...> will be transferred from the browser to the Web server. This transferring (uploading) process is controlled by a properly written <FORM...> tag as:
  <FORM ACTION=receiving.php METHOD=post ENCTYPE=multipart/form-data>
Note that you must specify METHOD as "post" and ENCTYPE as "multipart/form-data" in order for the uploading process to work. The following PHP code, called logo_upload.php, shows you a complete FORM tag for file uploading:
<?php
  print("<html><form action=processing_uploaded_files.php"
    ." method=post enctype=multipart/form-data>\n");
  print("Please submit an image file a Web site logo for"
    ." fyicenter.com:<br>\n");
  print("<input type=file name=fyicenter_logo><br>\n");
  print("<input type=submit>\n");
  print("</form></html>\n");
?>