Friday 20 September 2013

Top 50 Php Interview Questions and Answers | Php Interview Questions PDF Download Free | PHP Interview Questions and Answers for Freshers PDF Free Download | PHP Interview Questions and Answers Ebook

Q1. What is PHP stands for?

Ans. Hyper text Pre Processor
Q2. What is PHP?

Ans. The PHP is a Hypertext Pre-processor and 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.
Q3. Who is the Father of PHP?

Ans. Rasmus Lerdorf
Q4. Which programming language does PHP resemble to?

Ans. PHP resemble to pearl and C
Q5. What the difference is between include and require?

Ans. Require () and include () are the same with respect to handling failures. However, require () results in a fatal error and does not allow the processing of the page. i.e. include will allow the script to continue.
Q6. What is the current version of PHP?

Ans. php 5.3
Q7. How can we create a database using PHP and MySQL?

Ans. We can create MySQL database with the use of
mysql_create_db ("Database Name")
Q8.What Is a Session?

Ans.It can be used to store information on the server for future use.
Q9. Is variable name case sensitive?

Ans. Yes variable name case sensitive and we cannot start a variable with number like $6name as a valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.
Q10. How can we execute a php script using command line?

Ans. 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.
Q11 : 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?

Answer : When to use GET or POST

The HTML 2.0 specification says, in section Form Submission (and the HTML 4.0 specification repeats this with minor stylistic changes):

–>If the processing of a form is idempotent (i.e. it has no lasting observable effect on the state of the
world), then the form method should be GET. Many database searches have no visible side-effects and make ideal applications of query forms.

–>If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.

//////////////////////////////////////////////////////////////////
Related Posts:
//////////////////////////////////////////////////////////////////
 

Q12 : Who is the father of PHP and explain the changes in PHP versions?

Answer : Rasmus Lerdorf is known as the father of PHP.PHP/FI 2.0 is an early and no longer supported version of PHP. PHP 3 is the successor to PHP/FI 2.0 and is a lot nicer. PHP 4 is the current generation of PHP, which uses the Zend engine under the hood. PHP 5 uses Zend engine 2 which, among other things, offers many additional OOPs features.

Q13 : How can we submit a form without a submit button?

Answer : The main idea behind this is to use Java script submit() function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit() method to onclick, onchange events of different inputs and perform the form submission. you
can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites).
Q14: What is the difference between mysql_fetch_object and mysql_fetch_array?

Answer : 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).

Q16 : What is the difference between $message and $$message?

Answer : It is a classic example of PHP’s variable variables. take the following example.

$message = “Raghav”;

$$message = “is a owner of http://sharag.wordpress.com/ “;

$message is a simple PHP variable that we are used to. But the $$message is not a very familiar face. It creates a variable name $mizan with the value “is a moderator of PHPXperts.” assigned. break it like this${$message} => $mizanSometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically.

Q17 : How the form data is transmitted?

–> If the method is “get” – -, the user agent takes the value of action, appends a ? to it, then appends the form data set, encoded using the application/x-www-form-urlencoded content type. The user agent then traverses the link to this URI. In this scenario, form data are restricted to ASCII codes.
–> If the method is “post” –, the user agent conducts an HTTP post transaction using the value of the action attribute and a message created according to the content type specified by the enctype
attribute.

Quote from CGI FAQ

Firstly, the the HTTP protocol specifies differing usages for the two methods. GET requests should always be idempotent on the server. This means that whereas one GET request might (rarely) change some state on the Server, two or more identical requests will have no further effect.

This is a theoretical point which is also good advice in practice. If a user hits “reload” on his/her browser, an identical request will be sent to the server, potentially resulting in two identical database or guestbook entries, counter increments, etc. Browsers may reload a GET URL automatically, particularly if cacheing is disabled (as is usually the case with CGI output), but will typically prompt the user before re-submitting a POST request. This means you’re far less likely to get inadvertently-repeated entries from POST.

GET is (in theory) the preferred method for idempotent operations, such as querying a database, though it matters little if you’re using a form. There is a further practical constraint that many systems have built-in limits to the length of a GET request they can handle: when the total size of a request (URL+params) approaches or exceeds 1Kb, you are well-advised to use POST in any
case.

I would prefer POST when I don’t want the status to be change when user resubmits. And GET
when it does not matter.

Q18 : How can we extract string ‘hotmail.com ‘ from a string raghav.cool@hotmail.com using regular expression of PHP?

Answer : preg_match(”/^http://.+@(.+)$/”,’raghav.cool@hotmail.com’,$found);
echo $found[1];

Q19 : How can we create a database using PHP and MySQL?

Answer : We can create MySQL Database with the use of mysql_create_db(“Database Name”).

Q20: What are the differences between require and include, include_once and require_once?
Answer :The include() statement includes and evaluates the specified file.The documentation below also applies to require(). The two constructs are identical in every way except how they handle
failure. include() produces a Warning while require() results in a Fatal Error. In other words, use
require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. 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. As the name suggests, it will be included just once.include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc. require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function
redefinitions, variable value reassignments, etc.

Q21 : Can we use include (”abc.PHP”) two times in a PHP page “makeit.PHP”?

Answer : Yes we can use include() more than one time in any page though it is not a very good practice.

Q22 : 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)) ?

Answer :  

Total 5 types of tables we can create

1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM

MyISAM is the default storage engine as of MySQL 3.23 and as a result if we do not specify the table name explicitly it will be assigned to the default engine.

Q23 : Functions in IMAP, POP3 AND LDAP?

Answer : You can find these specific information in PHP Manual.

Q24 : How can I execute a PHP script using command line?

Answer : As of version 4.3.0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface. 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.

//////////////////////////////////////////////////////////////////
Related Posts:
//////////////////////////////////////////////////////////////////

Q25 : Suppose your Zend engine supports the mode <? ?>. Then how can you configure your PHP Zend engine to support <?php ?>mode ?

Answer
In php.ini file:
set
short_open_tag=on
to make PHP support

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

Answer : We can find the detail documentation about different paypal integration process at the following site PayPal PHP
SDK : http://www.paypaldev.org/

Q27 : What is meant by nl2br()?

Answer :  

Inserts HTML line breaks
(
)
before all newlines in a string string nl2br (string); Returns string with ” inserted before all newlines.
For example: echo nl2br(”god bless/n you”) will output “god bless
you” to your browser.

Q28: Draw the architecture of Zend engine?

Answer : The Zend Engine is the internal compiler and runtime engine used by PHP4. Developed by Zeev Suraski and Andi Gutmans, the Zend Engine is an
abbreviation of their names. In the early days of PHP4, it worked as follows:
Top 50 Php Interview Questions and Answers 

The PHP script was loaded by the Zend Engine and compiled into Zend opcode. Opcodes, short for operation codes, are low level binary instructions. Then the opcode was executed and the HTML generated sent to the client. The opcode was flushed from memory after execution.Today, there are a multitude of products and techniques to help you speed up this process. In the following diagram, we show the how modern PHP scripts work; all the shaded boxes are optional.

Top 50 Php Interview Questions and Answers
PHP Scripts are loaded into memory and compiled into Zend opcodes.

Q29: What are the current versions of apache, PHP, and MySQL?

Answer : As of Aug 2008 the current versions are PHP: php5.2.6
MySQL: MySQL 5.1.2
Apache: Apache 2.2.9
Note: visit this below website
http://www.php.net/,
http://dev.mysql.com/downloads/mysql/,
http://www.apache.org/ to get current

Q30 : What are the reasons for selecting lamp (Linux, apache, MySQL,PHP) instead of combination of other software programs, servers and operating systems?

Answer : All of those are open source resource. Security of Linux is very very more than windows. Apache is a better server that IIS both in functionality and security. MySQL is world most popular open source database. PHP is more faster that asp or any other scripting language.

Q31: How can we encrypt and decrypt a data present in a MySQL table using MySQL?
 
Answer : AES_ENCRYPT () and AES_DECRYPT ()

Q32 : How can we encrypt the username and password using PHP?

Answer : The functions in this section perform encryption and decryption, and compression and uncompression:

Encryption Decryption
AES_ENCRYT() AES_DECRYPT()
ENCODE() DECODE()
DES_ENCRYPT() DES_DECRYPT()
ENCRYPT() Not available
MD5() Not available
OLD_PASSWORD() Not available
PASSWORD() Not available
SHA() or SHA1() Not available
Not available UNCOMPRESSED_LENGTH()

Q33 : What are the features and advantages of object-oriented programming?

Answer :  
One of the main advantages of OO programming is its ease of modification; objects can easily be modified and added to a system there by reducing maintenance costs. OO programming is also considered to be better at modeling the real world than is procedural programming. It allows for more complicated and flexible interactions. OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns. For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused. Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.

Q34 : What are the differences between procedure-oriented languages and object-oriented languages?


//////////////////////////////////////////////////////////////////
Related Posts:
//////////////////////////////////////////////////////////////////

Answer : Traditional programming has the following characteristics:Functions are written sequentially, so that a change in programming can affect any code that follows it. If a function is used multiple times in a system (i.e., a piece of code that manages the date), it is often simply cut and pasted into each program (i.e., a change log, order function, fulfillment system, etc). If a date change is needed (i.e., Y2K when the code needed to be changed to handle four numerical digits instead of two), all these pieces of code must be found, modified, and tested. Code (sequences of computer instructions) and data (information on which the instructions operates on) are kept separate. Multiple sets of code can access and modify one set of data. One set of code may rely on data in multiple places. Multiple sets of code and data are required to work together. Changes made to any of the code sets and data sets can cause problems through out the system.Object-Oriented programming takes a radically different approach:Code and data are merged into one indivisible item – an object (the term “component” has also been used to describe an object.) An object is an abstraction of a set of real-world things (for example, an object may be created around “date”) The object would contain all information and
functionality for that thing (A date object it may contain labels like January, February, Tuesday, Wednesday.

It may contain functionality that manages leap years, determines if it is a business day or a holiday, etc., See Fig. 1). Ideally, information about a particular thing should reside in only one place in a system.The information within an object is encapsulated (or hidden) from the rest of the system. 
A system is composed of multiple objects (i.e., date function, reports, order processing, etc., See Fig 2). When one object needs information from another object, a request is sent asking for specific information.  (for example, a report object may need to know what today’s date is and will send a request to the date object) These requests are called messages and each object has an interface that manages messages. oops programming languages include features such as “class”, “instance”, “inheritance”, and “polymorphism” that increase the power and flexibility of an object.


//////////////////////////////////////////////////////////////////
Related Posts:
//////////////////////////////////////////////////////////////////

Q35 : What is the use of friend function?
  
Answer : Sometimes a function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class. A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.


Q36 : What are the differences between public, private, protected,static, transient, final and volatile?

Answer :  

Public: Public declared items can be accessed everywhere.


Protected: Protected limits access to inherited and parent classes (and to the class that defines the item).


Private:Private limits visibility only to the class that defines the item.


Static: A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.


Final: Final keyword prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.


Transient: A transient variable is a variable that may not be serialized.


Volatile: a variable that might be concurrently modified by multiple threads should be declared volatile. Variables declared to be volatile will not be optimized by the compiler because their value can change at any time.


Q37 : What are the different types of errors in PHP?

Answer

Three are three types of errors:1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script – for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all – although, as you will see, you can change this default behavior.2. Warnings: These are more serious errors – for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.3. Fatal errors: These are critical errors – for example,
instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.
//////////////////////////////////////////////////////////////////
Related Posts:
//////////////////////////////////////////////////////////////////


Q38 : What is the functionality of the function strstr and stristr?

Answer : strstr:

Returns part of haystack string from the first occurrence of needle to the end of haystack.If needle is not found, returns FALSE. If needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This function is case-sensitive. For case-insensitive searches, use stristr().

Q39: What are the differences between PHP 3 and PHP 4 and PHP 5?

Answer : PHP 3 is most procedure oriented and , PHP4 and PHP5 aer object oriented. For more details
http://php.net/


Q40 : How can we convert asp pages to PHP pages?


Answer : There are lots of tools available for asp to PHP conversion. you can search Google for that. the best one is available at http://asp2php.naken.cc/

Q41: What is the functionality of the function htmlentities?

Answer : Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.


Q42 : How can we get second of the current time using date function?


Answer : $second = date(”s”);

Q43 : How can we convert the time zones using PHP?

Answer :  
By using date_default_timezone_get and date_default_timezone_set function on PHP 5.1.0
<!–p// Discover what 8am in Tokyo relates to on the East Coast of the US
// Set the default timezone to Tokyo time:
date_default_timezone_set(’Asia/Tokyo’);

// Now generate the timestamp for that particular timezone, on Jan 1st, 2000
$stamp = mktime(8, 0, 0, 1, 1, 2000);

// Now set the timezone back to US/Eastern
date_default_timezone_set(’US/Eastern’);

// Output the date in a standard format (RFC1123), this will  print:
// Fri, 31 Dec 1999 18:00:00 EST
echo ‘

‘, date(DATE_RFC1123, $stamp) ,’
‘; ?>

Q44 : What is meant by urlencode and urldecode?

Answer : URLencode returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs. It is encoded the same way that the posted data from a WWW form
is encoded, that is the same way as in application/x-www-form-urlencoded media type. urldecode decodes any %## encoding in the given string.
 
Q45 : What is the difference between the functions unlink and unset?


Answer : unlink() deletes the given file from the file system.
unset() makes a variable undefined.

Q46 : How can we register the variables into a session?

Answer : $_SESSION[’name’] = “APK”;

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

Answer : To know the Image type use exif_imagetype () function
To know the Image size use getimagesize () function
To know the image width use imagesx () function
To know the image height use imagesy() function

Q48 : How can we get the browser properties using PHP?

Answer : By using
$_SERVER[’HTTP_USER_AGENT’] variable.


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


Answer : By default the maximum size is 2MB. and we can change the following setup at php.iniupload_max_filesize = 2M

Q50 : How can we increase the execution time of a PHP script?

Answer : by changing the following setup at php.inimax_execution_time = 30; Maximum execution time of each script, in seconds

Keywords:

basic php interview questions and answers pdf download, free php interview questions and answers pdf, free download php interview questions and answers pdf online, php interview questions and answers for freshers pdf download, php interview questions pdf download free, php interview answers free, best php interview, top 10 php interview, top 50 php interview, top 100 php interview questions

0 comments:

  © Blogger templates Newspaper III by Ourblogtemplates.com 2008

Back to TOP