:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:         
  passwords:  

PHP Interview Questions and answers [Part 1]

The General Php Interview Questions consists the most frequently asked questions in PHP. This list of 100+ questions guage your familiarity with the Php platform. The q&a have been collected over a period of time from various blogs, forums and other similar Php sites

1. General (Part 1)

    1.1 What is Php?
    1.2 What is the difference between $message and $$message?
    1.3 What are the differences between require and include, include_once?
    1.4 What is meant by urlencode and urldecode?
    1.5 What is the difference between mysql_fetch_object and mysql_fetch_array?
    1.6 How can I execute a PHP script using command line?
    1.7 How can we encrypt the username and password using PHP?
    1.8 How do you pass a variable by value?
    1.9 How can we send mail using JavaScript?
    1.10 What is SAP R/3?
    1.11 What is the difference between ereg_replace() and eregi_replace()?
    1.12 When are you supposed to use endif to end the conditional statement?
    1.13 What is the functionality of the function strstr and stristr?
    1.14 If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?
    1.15 objects passed by value or by reference?
    1.16 What are the differences between DROP a table and TRUNCATE a table?
    1.17 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?
    1.18 WWhat’s the special meaning of __sleep and __wakeup?
    1.19 How can we submit a form without a submit button?
    1.20 Would you initialize your strings with single quotes or double quotes?

1.1 What is PHP?

The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.


1.2 What is the difference between $message and $$message?

$message is a simple variable whereas $$message is a reference variable. Example:
$user = 'bob'
is equivalent to
$holder = 'user';
$$holder = 'bob';


1.3 What are the differences between require and include, include_once?

Anwser 1:
require_once() and include_once() are both the functions to include and evaluate the specified file only once. If the specified file is included previous to the present call occurrence, it will not be done again. But require() and include() will do it as many times they are asked to do.
Anwser 2:
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.4 What is meant by urlencode and urldecode?

urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs. urldecode() returns the URL decoded version of the given string.


1.5 What is the difference between mysql_fetch_object and mysql_fetch_array?

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array


1.6 How can I execute a PHP script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program. Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.


1.7 I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?

International Demonstration and Education System. A sample application provided for faster learning and implementation.


1.8 How can we encrypt the username and password using PHP?

Answer 1
You can encrypt a password with the followingMysql>SET PASSWORD=PASSWORD("Password");
Answer 2
You can use the MySQL PASSWORD() function to encrypt username and password. For example, INSERT into user (password, ...) VALUES (PASSWORD($password”)), ...);


1.9 How do you pass a variable by value?

Just like in C++, put an ampersand in front of it, like $a = &$b


1.10 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:mailid@domain.com?subject=..."; return true; }


1.11 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.


1.12 When are you supposed to use endif to end the conditional statement?

When the original if was followed by : and then the code block without braces.


1.13 What is the functionality of the function strstr and stristr?

strstr() returns part of a given string from the first occurrence of a given substring to the end of the string. For example: strstr("user@example.com","@") will return "@example.com". stristr() is idential to strstr() except that it is case insensitive.


1.14 If the variable $a is equal to 5 and variable $b is equal to character a, what’s the value of $$b?

100, it’s a reference to existing variable.


1.15 Are objects passed by value or by reference?

Everything is passed by value.


1.16 What are the differences between DROP a table and TRUNCATE a table?

DROP TABLE table_name - This will delete the table and its data. TRUNCATE TABLE table_name - This will delete the data of the table, but not the table definition.


1.17 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?

Anwser 1:
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. Anwser 2:
When you want to send short or small data, not containing ASCII characters, then you can use GET” Method. But for long data sending, say more then 100 character you can use POST method. Once most important difference is when you are sending the form with GET method. You can see the output which you are sending in the address bar. Whereas if you send the form with POST” method then user can not see that information


1.18 What’s the special meaning of __sleep and __wakeup?

__sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.


1.19 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: Submit Me


1.20 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.

Copyright 2007, Megasolutions Ltd