PHP INTERVIEW QUESTIONS AND ANSWERS
1. What is the difference between a static and Dynamic Web
site?
- A static website is one that is written in HTML only.
- Each page is a separate document and there is no database that it draws on.
- What this means functionally is that the only way to edit the site is to go into each page and edit the HTML - So you would have to do it yourself using a web page editor such as FrontPage or Dreamweaver, or pay your web developer to make updates for you.
- A dynamic website is created by webdevelopers who are strong in ASP.Net, PHP, JAVA and more... This website pages contains data is retrieved from certain database.
- Each time the viewer entering a page, the contents of that page is retrieved from the database.
- The administrator can change the content and images from admin panel. This is one that changes or customizes itself frequently and automatically.
2. What is the meaning of Open Source Software?
- Open-Source Software (OSS) is computer software that is available in source code form: the source code and certain other rights normally reserved for copyright holders are provided under a software license that permits users to study, change, improve and at times also to distribute the software.
- Open Source Software means it is a free software and no need to buy, we can use full functionallities from this software with certain Terms & Conditions.
- This license allows modifications and derived works, and allows us to be distributed under the same terms as the license of the original software.
3. Why was PHP developed, what it is used for, and where can
you get it?
- PHP developed for less script, time saving, Free Open Source Software and runs on different platforms such as Windows, Linux, Unix, etc. PHP compatible with almost all servers used today such as Apache, IIS, etc.
- The PHP scripting language resembles JavaScript, Java, and Perl, These languages all share a common ancestor, the C programming language.
- PHP has full access to the information that the server has, and very little access to information that the client has.
- In fact, it only has information that the client tells the server and that the server passes on to PHP.
- Because it is on the server, however, PHP cannot be modified by the client. While you cannot necessarily trust the information that the client gives to PHP, you can trust that your PHP is doing what you told it to do.
- Because PHP is on the server end, your PHP scripts can affect your server -- such as by keeping an activity log or updating a database.
4. What are the benefits of using PHP and MySQL?
- One of the main reasons that businesses choose PHP is its simplicity and ease of use. PHP competes against a number of other web scripting solutions such as Active Server Pages and PERL, but none of these languages are as easy to learn as PHP.
- Further, some languages require a moderate amount of programming background before a developer can get up to speed in development.
- With PHP, however, even non-programmers have been able to develop web-based solutions within a matter of days after going through the basic tutorials on PHP.
- PHP commands are simply embedded into the same web page with HTML commands, and execute on the server to deliver the web pages to the user.
- Another big advantage of PHP is its interoperability with multiple operating systems.
- A company can use PHP with either Linux, Windows or Macs for example. They can also use PHP with the popular open source Apache server.
- Compare that with Microsoft’s Active Server Pages, by contrast, which is primarily designed for Microsoft-enabled servers.
- Portability is becoming a chief concern for businesses that use one or more operating systems in their businesses.
- Businesses save money by using PHP to leverage their existing I.S. resources rather than investing large sums of money to purchase proprietary products.
5. What is PHP?
- PHP stand for Hypertext Preprocessor.
- PHP is a Server Side Scripting Language.
- PHP is a Open Source Software. PHP free to download and use.
- PHP scripts are executed on server.
- PHP supports many databases such as MYSQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.,
6. What are the
differences between GET and POST methods in form submitting
On the server side,
the main difference between GET and POST is where the submitted is stored. The $_GET array stores data submitted by the GET method. The $_POST array stores data submitted by the POST method.
On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POSTmethod will not be displayed anywhere on the browser.
GET method is mostly used for submitting a small amount and less sensitive data.
POST method is mostly used for submitting a large amount or sensitive data.
On the browser side, the difference is that data submitted by the GET method will be displayed in the browser’s address field. Data submitted by the POSTmethod will not be displayed anywhere on the browser.
GET method is mostly used for submitting a small amount and less sensitive data.
POST method is mostly used for submitting a large amount or sensitive data.
7. How can we submit
from without a submit button?
We can use a simple JavaScript code
linked to an event trigger of any form field. In the JavaScript code, we can
call the document.form.submit(); function to submit the form.
8. How can we get the
browser properties using php?
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$browser = get_browser(null, true);
print_r($browser);
?>
9. 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. Sessions are commonly used to store temporary data to allow multiple
PHP pages to offer a complete functional transaction for the same visitor.
10. How can we register
the variables into a session?
session_register($ur_session_var);
?>
?>
11. How do you destroy
a particular or all Sessions?
session_start();
// store session data
$_SESSION['views']=1;
unset($_SESSION['views']); // If you wish to delete some session data, you can use the unset()
session_destroy(); // You can also completely destroy the session by calling the session_destroy() function. session_destroy() will reset your session and you will lose all your stored session data.
?>
12. How many ways we
can pass the variable through the navigation between the pages?
·
Register the variable into the session
·
Pass the variable as a cookie
·
Pass the variable as part of the URL
13. What are the
different functions in sorting an array?
·
asort()
·
arsort()
·
ksort()
·
krsort()
·
uksort()
·
sort()
·
natsort()
·
rsort()
14. How can we know the
total number of elements of Array?
· sizeof($array_var)
· count($array_var)
·
If we just pass a simple var instead of
a an array it will return 1.
15. What type of
headers that PHP supports?
$_SERVER[‘HTTP_ACCEPT’]
16. How can we extract
string ‘abc.com’ from a string ‘http://info@abc.com’ using regular _expression
of php?
We can use the preg_match()
function with “/.*@(.*)$/” as the regular expression pattern.
For example:
preg_match("/.*@(.*)$/","http://info@abc.com",$data);
echo $data[1];
?>
For example:
preg_match("/.*@(.*)$/","http://info@abc.com",$data);
echo $data[1];
?>
17. How can we create a
database using php?
mysql_create_db();
18. Explain include(),
include_once, require() and require_once.
include()
The include() function takes all the content in a specified file and includes it in the current file. If an error occurs, the include() function generates a warning, but the script will continue execution.
include_once()
File will not be included more than once. If we want to include a file once only and further calling of the file will be ignored then we have to use the PHP function include_once().
require()
The require() function is identical to include(), except that it handles errors differently. The require() generates a fatal error, and the script will stop.
require_once()
The required file is called only once when a page is open and further calling of the file will be ignored.
19. What are the
different types of errors in php?
· 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 behaviour.
· 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.
· 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 behaviour is to display them to the user when
they take place.
·
If we just pass a simple var instead of
a an array it will return 1.
20. What are the
Formatting and Printing Strings available in PHP?
Function
|
Description
|
printf()
|
Displays a formatted string
|
sprintf()
|
Saves a formatted string in a variable
|
fprintf()
|
Prints a formatted string to a file
|
number_format()
|
Formats numbers as strings
|
21. How to find a
length of a string?
strlen()
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.
For example:
strstr("user@example.com","@") will return "@example.com".
stristr() is idential to strstr() except that it is case insensitive.
How can we get second of the
current time using date function?
$second = date(“s”);
?>
22. What is the
difference between the functions unlink and unset?
unlink() deletes the given
file from the file system.
unset() makes a variable undefined.
unset() makes a variable undefined.
23. 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.
24. What is the
difference between characters \023 and \x23?
The first one is octal 23, the
second is hex 23.
25. What is the
difference between PHP4 and PHP5?
PHP4 cannot support
oops concepts and Zend engine 1 is used.
PHP5 supports oops concepts and Zend engine 2 is used. Error supporting is increased in PHP5. XML and SQLLite will is increased in PHP5.
PHP5 supports oops concepts and Zend engine 2 is used. Error supporting is increased in PHP5. XML and SQLLite will is increased in PHP5.
No comments:
Post a Comment