Upwork Test Answers: Get all the correct answers of most recent and possible Upwork Tests A to Z (Updated on Jan, 2016)
Cover Letter Templates: These cover letter samples are not only for Upwork job, but also you will have some idea about your real life job
Freelance Profile Overviews: Different Profile samples and overviews of experts, advanced and intermediate level freelancers
For Newbie of Upwork: Upwork Help - How to apply for a job in Upwork with 10 most important articles about Upwork

A to Z View - All Upwork Test Answers

PHP - Job Interview Questions and Answers

Here you will find all the possible answers of Upwork PHP Job Interview Questions and Answers that you might be asked by your Upwork employer:

1. Can we use include ("xyz.PHP") two times in a PHP page "index.PHP"?

Yes we can use include("xyz.php") more than one time in any page. but it create a prob when xyz.php file contain some functions declaration then error will come for already declared function in this file else not a prob like if you want to show same content two time in page then must include it two time not a prob 

2. Describe functions STRSTR() and STRISTR.

Both the functions  are used to find the first occurrence of a string. Parameters includes: input  String, string whose occurrence needs to be found, TRUE or FALSE (If TRUE, the  functions return the string before the first occurrence.

STRISTR is similar to STRSTR. However, it is case-insensitive
E.g. strstr ($input_string, string)

3. Echo vs. print statement. 

echo() and print() are language constructs in PHP, both are used to output strings. The speed of both statements is almost the same.

echo() can take multiple expressions whereas print cannot take multiple expressions.

Print return true or false based on success or failure whereas echo doesn't return true or false.

4. Echo vs. print statement?

echo() and print() are language constructs in PHP, both are used to output strings. The speed of both statements is almost the same.

echo() can take multiple expressions whereas print cannot take multiple expressions. Print return true or false based on success or failure whereas echo doesn't return true or false.

5. Explain how to submit form without a submit button in PHP.

A form can be submitted in various ways without using submit button.

Submitting a form by clicking a link
Submitting a form by selecting an option from drop down box with the invocation of onChange event
Using java script : document.form.submit();
Using header(''location:page.php'');

6. Explain how to submit form without a submit button.

We can achieve the above task by using JavaScript code linked to an event trigger of any form field and call the document.form.submit() function in JavaScript code.

7. Explain the difference between $message and $$message in PHP

$message is a variable and $$message is a variable of another variable. For example

$Message = "YOU";
$you= "Me";

echo $message //Output:- you
echo $$message //output :-Me

$$message allows the developer to change the name of the variable dynamically.

8. Explain the differences between require and include, include_once?

Include() will include the file specified.

Include_once() will include the file  only once even if the code of the file has been included before.

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.

9. Explain the different types of errors in PHP.

Notices, Warnings and Fatal errors are the types of errors in PHP


Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.


Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.

Fatal errors:

Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.

10. Explain the importance of the function html entities.

The htmlentities() function converts characters to HTML entities.

11. Explain the purpose of output buffering in PHP?

Output buffering in PHP buffers a scripts output. This buffer can be edited

before returning it to the client. Without output buffering, PHP sends data to

the web server as soon as it is ready. Output buffering "send" cookies at any

point in the script. Cookies do not have to be necessarily sent near the start

of page. Output buffers are stackable and hence sending to output is by choice.

12. How can we convert the time zones using PHP?

By using date_default_timezone_get and
  date_default_timezone_set function on PHP 5.1.0
  // Discover what 8am in Tokyo relates to on the East Coast
  of the US
  // Set the default timezone to Tokyo time:
  // 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
  // Output the date in a standard format (RFC1123), this
  will print:
  // Fri, 31 Dec 1999 18:00:00 EST
  echo '<p>', date(DATE_RFC1123, $stamp) ,'</p>';?>

13. How can we increase the execution time of a PHP script?

By default the PHP script takes 30secs to execute. This time is set in the

php.ini file. This time can be increased by modifying the max_execution_time in

seconds. The time must be changed keeping the environment of the server. This

is because modifying the execution time will affect all the sites hosted by the


14. How do we know properties of the browser?

You can gather a lot of information about a person's computer by using $_SERVER['HTTP_USER_AGENT'].
  This can tell us more about the user's operating system, as well as their browser. For example I am revealed
  to be Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.3
  when visiting a PHP page.
  This can be useful to programmers if they are using special features that may not work for everyone, or if
  they want to get an idea of their target audience. This also is important when using the get_browser() function
  for finding out more information about the browser's capabilities. By having this information the user can be
  directed to a version of your site best suited to their browser.
  get_browser() attempts to determine the capabilities of the user's browser. This is done by looking up the
  browser's information in the browscap.ini file.
  echo $_SERVER['HTTP_USER_AGENT'] . "<hr />\n";
  $browser = get_browser();

foreach ($browser as $name => $value)
  echo "<b>$name</b> $value <br />\n";


15. How do you create sub domains using PHP?

Wild card domains can be used. Sub domains can be created by first creating a sub directory in the /htdocs folder. E.g. /htdocs/mydomain. Then, the host file needs to be modified to define the sub domain. If the sub domains are not configured explicitly, all requests should be thrown to the main domain.

16. How error handling is being handled by PHP?

Error handling is very important in every programming language. PHP uses the trigger to print the error in a program. The example statement is given below:
  If ($height_of_door > $height_of_house)
  { trigger_error(''Impossible condition'',E_USER_ERROR); }
  The E_USER_ERROR in the statement tells PHP that the condition is an error. Impossible condition is a string message which is displayed when an error is encountered. If the condition comes out to be true then the following message is displayed:
  Fatal error: Impossible condition
  E_USER_WARNING or E_USER_NOTICE can be used instead of E_USER_ERROR, to have PHP treat the condition as a warning or notice. Own statements can be written to perform error handling actions such as send a message, log a message or stop the script. For example:
  If ($height_of_door > $height_of_house)
  echo ''This is impossible<br>'';
  If $height_of_door is larger than $height_of_house, the message is echoed, and exit() stops the script.
  Die statement can be used to display an error message when a function fails.

17. How many different types of messages available in PHP?

1. Error message: is received when the script has some problem that is preventing it from running correctly. The message consists of the possible solution or identification of the problem. Ex: Parse error: occurs when there is something gets missed while writing the script.
  2. Warning message: is received when the script find out some problem that doesn't allow the script to run. These messages are not of very high priority but quite essential to show that there is something wrong with the script. Ex: if you write print_r() instead of print_r($varname) then a warning will occur like this:
  Warning: print_r() expects at least 1 parameter, 0 given
  The script will execute in continuation.
  3. Notice: is received when there is a condition where a script might have an error or may be it is working. Ex: echo variables that don't exist.

18. How many ways I can redirect a PHP page?

a. Header function in PHP redirects to a new URL


header("Location: http://www.redirecturl.com/");

b. http_redirect() is also used to redirect to a new page or URL.

void http_redirect ( [string url [, array params [, bool session = FALSE [, int status]]]] )

Here, the URL is the path of the new page. params can be some query parameters followed by whether the session information needs to be passed and the custom response status code.

19. How PHP statement is different from PHP script?   

The difference between PHP statement and PHP script is that statements are set of instructions that tell PHP to perform an action. PHP script consists of a series of PHP statements that it uses for execution. PHP executes statements one at a time till it reaches the end of the script. Example is as follows:
  PHP statement: echo ''Hi'';
  PHP script: if (time = midnight)
  {put on pajamas;
  brush teeth;
  go to bed;}

20. How the web server interprets PHP and interacts with the client?

After installing and configuring the PHP, the web When PHP is installed, the Web server looks for PHP code that is embedded in HTML file with its extension. The extensions which are used are .php or .phtml. When web server receives a request for the file with an appropriate extension, HTML statements are processed and PHP statements are executed on the server itself. When the processing gets over the output is being shown in HTML statements.

21. How to Create a Cookie & destroy it in PHP?

  variable - name of the cookie variable
  variable - value of the cookie variable
  time - expiry time
  Example: setcookie(”test”,$i,time()+3600);
  Test - cookie variable name
  $i - value of the variable ‘Test’
  time()+3600 - denotes that the cookie will expire after an one hour.
  Destroy a cookie by specifying expiry time
  Example: setcookie(”test”,$i,time()-3600); // already expired time
  Reset a cookie by specifying its name only

22. How to create reusable code in PHP?

Applications created in PHP often perform the same task in same script or in different scripts. To create a reusable code functions are used. Functions are group of PHP statements that perform a specific task. Example:
  A header and footer can be created for all the web pages which has to be used again and again.
  echo '<img src=''greenrule.jpg'' width=''100%'' height=''7'' />
  <address>My Great Company
  <br />1234 Wonderful Rd.
  <br />San Diego, CA 92126
  <p>or send questions to
  <a href=''mailto:sales@company.com''>sales </a>
  <img src=''greenrule.jpg'' width=''100%'' height=''7'' />';
  Instead of typing header and footer for each page, a function can be created and used to add footer and header in every page. The function can be named as:

23. How to set cookies in PHP?

The function setcookie() is used to define a cookie that is to be sent along with HTTP headers. The cookie must be sent prior to any output from the script as is the protocol restriction. After setting the cookies, they can be used when the next page is loaded by using $_COOKIE or $HTTP_COOKIE_VARS arrays.

24. How to set cookies? How to reset/destroy a cookie?
Setting cookie in php:

Cookies in PHP can be set using the setcookie() function. This must appear before the HTML tag,


Setcookie(name, value, expire, path, domain);

Example: here, the cookie name sample is assigned a value jim. The cookie expires after an hour.

Setcookie(''sample'', ''jim'', time()+3600);

Reset/destroy cookie

Cookies can be deleted either by the client or by the server. Clients can easily delete the cookies by locating the Cookies folder on their system and deleting them. The Server can delete the cookies in two ways:

  •  Reset a cookie by specifying expiry time
  •  Reset a cookie by specifying its name only

25. how to track user logged out or not? when user is idle ?

By checking the session variable exist or not while loading th page. As the session will exist longer as till browser closes. The default behavior for sessions is to keep a session open indefinitely and only
to expire a session when the browser is closed. This behavior can be changed in the php.ini file by altering the line 
  session.cookie_lifetime = 0 to a value in seconds. If you wanted the session to finish in 5 minutes you would set this to
  session.cookie_lifetime = 300 and restart your httpd server.

26. How to upload files using PHP?

- Select a file from the form using <inupt type=''file''>
- Specify the path into which the file is to be stored.
- Insert the following code in php script to upload the file.

move_uploaded_file($_FILES["file"]["tmp_name"], "myfolder/" . $_FILES["file"]["name"]);

27. How to use HTTP Headers inside PHP? Write the statement through which it can be added?

HTTP headers can be used in PHP by redirection which is written as:
<?header('Location: http://www.php.net')?>
The headers can be added to HTTP response in PHP using the header(). The response headers are sent before any actual response being sent. The HTTP headers have to be sent before taking the output of any data. The statement above gets included at the top of the script.

28. PHP $message vs. $$message.

$message is a variable with a fixed name. $$message is a variable whose name is stored in $message.

If $message contains "var", $$message is the same as $var.

29. PHP being an open source is there any support available to it?

PHP is an open source language, and it is been said that it has very less support online and offline. But, PHP is all together a different language that is being developed by group of programmers, who writes the code. There is lots of available support for PHP, which mostly comes from developers and PHP users.

30. PHP how to know user has read the email?

Using Disposition-Notification-To: in mailheader we can get read
  Add the possibility to define a read receipt when sending an email.
  It’s quite straightforward, just edit email.php, and add this at
  vars definitions:
  var $readReceipt = null;
  And then, at ‘createHeader’ function add:
  if (!empty($this->readReceipt)) {
  $this->__header .= ‘Disposition-Notification-To: ‘ . $this-
  >__formatAddress($this->readReceipt) . $this->_newLine;

31. Short note on passing parameter by reference and returning parameter by reference with examples.

Passing parameter by reference: In PHP, variables can be passed by reference so as to modify them. 
Variables, statements which have new and references returned from function can be passed.

Example: references returned from function

Function &sample()
$a =1;
Return &a;

Returning parameter by reference: Returning parameter by reference is used when a function to find to which variable a reference should be bound.

$obj = new foo;
$myValue = &$obj->getValue(); // $myValue is a reference to $obj-value, which is 42.
$obj->value = 2;
echo $myValue;

32. What are escaping characters? Explain with an example?   

Special characters are the characters that have some special meaning attached to it. Example is $, #, % etc. A backslash (\) before the special symbol is known as escaping characters. For example, two strings produce the same output:
  $string = 'The variable name is $var1';
  $string = ''The variable name is \$var1'';
  The output from either string is the following:
  The variable name is $var1
  Suppose you want to store a string as follows:
  $string = _Where is Tom'_s house_;
  echo $string;
  The sting can be interpreted by PHP by putting a backslash (\) in front of the single quote. The backslash tells PHP that the single quote does not have any special meaning; it's just an apostrophe. Example:
  $string = _Where is Tom\'_s house_;

33. what are magic methods?

Magic methods are the members functions that is available to all the
  instance of class Magic methods always starts with "__". Eg.
  __construct All magic methods needs to be declared as public To use
  magic method they should be defined within the class or program
  scope Various Magic Methods used in PHP 5 are: __construct()
  __destruct() __set() __get() __call() __toString() __sleep()
  __wakeup() __isset() __unset() __autoload() __clone()

34. What are the differences between Get and post methods?

There are some defference between GET and POST method
  1. GET Method have some limit like only 2Kb data able to send forrequest
  But in POST method unlimited data can we send

  2. when we use GET method requested data show in url but
  Not in POST method so POST method is good for send sensetive

35. What are the differences between PHP 3 and PHP 4 and PHP5?

There are lot of difference among these three version of php
  1>Php3 is oldest version after that php4 came and current version is
  php5 (php5.3) where php6 have to come
  2>Difference mean oldest version have less functionality as compare
  to new one like php5 have all OOPs concept now where as php3 was
  pure procedural language constructive like C
  In PHP5 1. Implementation of exceptions and exception handling
  2. Type hinting which allows you to force the type of a specific
  3. Overloading of methods through the __call function
  4. Full constructors and destructors etc through a __constuctor and
  __destructor function
  5. __autoload function for dynamically including certain include files
  depending on the class you are trying to create.
  6 Finality : can now use the final keyword to indicate that a method
  cannot be overridden by a child. You can also declare an entire class
  as final which prevents it from having any children at all.
  7 Interfaces & Abstract Classes
  8 Passed by Reference :
  9 An __clone method if you really want to duplicate an object
  10 Numbers of Functions Deprecated in php 5.x like
  session_register,register_globals, split(), call_user_method() etc

36. What are the differences between public, private, protected, static, transient, final and volatile?

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

37. What are the different components used in PHP for formatting?

The components that are used in PHP for formatting are as follows:
  1. %: it tells the start of the formatting instruction.
  2. Padding character (pad): is used to fill out the string when the value to be formatted is smaller than the width assigned. Pad can be a space, a 0, or any character preceded by a single quote (').
  3. -: A symbol meaning to left-justify the characters. If this is not included, the characters are right-justified.
  4. width: The number of characters to use for the value. If the value doesn't fill the width, the padding character is used to pad the value. For example, if the width is 5, the padding character is 0, and the value is 1, the output is 00001.
  5. dec: The number of decimal places to use for a number. This value is preceded by a decimal point.
  6. type: The type of value. Use s(string) for string, f (float) for numbers that you want to format with decimal places.

38. What are the different tables(Engine) present in MySQL,which one is default?

Following tables (Storage Engine) we can create
  1. MyISAM(The default storage engine IN MYSQL 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.
  An .frm file stores the table format. The data file has an .MYD
  (MYData) extension. The index file has an .MYI (MYIndex) extension.
  2. InnoDB(InnoDB is a transaction-safe (ACID compliant) storage
  engine for MySQL that has commit, rollback, and crash-recovery
  capabilities to protect user data.)
  3. Merge
  4. Heap (MEMORY)(The MEMORY storage engine creates tables
  with contents that are stored in memory. Formerly, these were
  known as HEAP tables. MEMORY is the preferred term, although
  HEAP remains supported for backward compatibility. )
  5. BDB (BerkeleyDB)(Sleepycat Software has provided MySQL
  with the Berkeley DB transactional storage engine. This storage
  engine typically is called BDB for short. BDB tables may have a
  greater chance of surviving crashes and are also capable of COMMIT

and ROLLBACK operations on transactions)
  7. FEDERATED (It is a storage engine that accesses data in tables
  of remote databases rather than in local tables. )
  8. ARCHIVE (The ARCHIVE storage engine is used for storing large
  amounts of data without indexes in a very small footprint. )
  9. CSV (The CSV storage engine stores data in text files using
  comma-separated values format.)
  10. BLACKHOLE (The BLACKHOLE storage engine acts as a "black
  hole" that accepts data but throws it away and does not store it.
 Retrievals always return an empty result)

39. What are the different types of errors in PHP?
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
  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

40. What are the different types of statements that are present in PHP?   

There are four kinds of PHP statements that are present. They are as follows:
  - Simple statement- these are the echo statements and end with a semicolon (;). PHP ignores white spaces between simple statements. Until it finds a semicolon it reads the statement.
  - Complex/Conditional statements: these are the statements which deal with certain conditions that have to be executed to meet certain specific requirements. These are if and else block or switch statements. PHP reads the complete statement and doesn't stop at the first semicolon it encounters. It looks for starting and ending braces to end the execution.
  - Looping statements: statements that are repeated in a block. The feature that enables you to execute the statements repeatedly is called as loop. For example: for loop, while loop, do..while loop.
41. What are the features and advantages of object-oriented programming?
One of the main advantages of OO programming is its ease of
  modification; objects can easily be modified and added to a system
  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
  also easier for non-technical personnel to understand and easier for
  them to participate in the maintenance and enhancement of a
  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
  modified for a specific system

42. What are the functions for IMAP in PHP?

Internet Message Access Protocol functions are used for retrieval of email messages. The clients using IMAP usually leaves messages on the email server until they are deleted explicitly by the user.

The following are some of the frequently used function from IMAP library.

  •  imap_open: To open an IMAP stream to a mail box
  •  imap_headers: Used to return headers for all emails
  •  imap_headerinfo: To read the email header.
  •  imap_delete: To mark the mails for deletion.
  •  imap_expunge: Delete all emails marked for deletion.
  •  imap_mail: To send an email message to a recipient.
  •  imap_body: To read the body of an email

43. What are the steps involved to run PHP?   

The steps which are involved and required to run PHP is as follows:
  1. Set up the web environment.
  2. Set up the web servers. There are many web servers that are available and the mostly used is Apaches which automatically remains installed with linux distribution and on windows it is easy to install. There are other servers like IIS (Internet information server) provided by Microsoft can be used to set up the web environment.
  3. Install the web server and PHP
  4. Update and administer the system for changes.

44. What are the various methods to pass data from one web page to another web page?

Different methods to pass data from one web page to another:

1. Store the data in a session variable. By storing the data, the data can be passed from one page to another.

2. Store data in a cookie: By storing data in a persistent cookie, data can be passed from one form to another.

3. Set the data in a hidden field and post the data using a submit button.

45. What does ODBC do in context with PHP?    

PHP supports many databases like dBase, Microsft SQL Server, Oracle, etc. But, it also supports databases like filePro, FrontBase and InterBase with ODBC connectivity. ODBC stands for Open Database connectivity, which is a standard that allows user to communicate with other databases like Access and IBM DB2.

46. What does type casting mean in PHP? Explain with an example?  

PHP automatically store the data and interprets according to itself. Type casting is a way to assign the variable according to your need and requirement and not allowing PHP to assign it automatically. To specify the type, it can be used like:
  $newint = (int) $var1;
  $newfloat = (float) $var1;
  $newstring = (string) $var1;
  The value in the variable on the right side of the equal sign is stored in the variable on the left side as the specified type.

47. What is a Persistent Cookie?

Cookies are used to remember the users. Content of a Persistent cookie remains unchanged even when the browser is closed. 'Remember me' generally used for login is the best example for Persistent Cookie.

48. What is a PHP Session?

What is a PHP Session?

PHP session allows you to store the user session, like their information on server for faster access and for later use like username, IP addresses, their actions etc. The information which is saved is temporary and can be deleted after the user is no longer active. Example of starting a PHP session is as follows:

session_start(); // start up your PHP session!

49. What Is a Session in PHP?

A PHP Session persist the user information to be used later. For example, user name, password, shopping item details. The session is temporary and will be removed soon after the user has left the web site. The session can be persisted for long term usage on databases like MySQL. Each session is identified by a unique Id number for every visitor. The first step to use PHP session is to start the session. The starting session must precede the operations like HTML or the other.

The statement session_start() starts the PHP session and registers the user's information on the server.

50. What is CAPTCHA in PHP?

Captcha are images with some characters/ digits on it. One need to type the characters or digits in the text box for the purpose of submitting. This avoids automatic submitting by an operation by other programs or a robot.

51. what is CURL?

CURL means Client URL Library

  curl is a command line tool for transferring files with URL syntax,
  DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP
  POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies,
  cookies, user+password authentication (Basic, Digest, NTLM,
  Negotiate, kerberos…), file transfer resume, proxy tunneling and a
  busload of other useful tricks.
  CURL allows you to connect and communicate to many different
  types of servers with many different types of protocols. libcurl
  currently supports the http, https, ftp, gopher, telnet, dict, file, and
  ldap protocols. libcurl also supports HTTPS certificates, HTTP POST,
  HTTP PUT, FTP uploading (this can also be done with PHP’s ftp
  extension), HTTP form based upload, proxies, cookies, and
  user+password authentication

52. What is difference between developing website using Java and PHP?

Both technologies are used for dynamic websites development.

PHP is an interpreter based technology where as java is compiler based(usually JSP).
PHP is open source where as JSP is not.
Web sites developed in PHP are much more faster compared to Java technology
Java is a distributed technology, which means N tier application can be developed, where as PHP is used only for web development.

53. What is difference between require_once(), require(), include()?

Difference between require() and require_once(): require() includes and evaluates a specific file, while

  require_once() does that only if it has not been included before (on the same page).
  So, require_once() is recommended to use when you want to include a file where you have a lot of functions
  for example. This way you make sure you don't include the file more times and you will not get the "function
  re-declared" error.
  Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to
  include is not found, while include() only produces a WARNING.
  There is also include_once() which is the same as include(), but the difference between them is the same as
  the difference between require() and require_once().

54. What is htaccess? Why do we use this and Where?

.htaccess files are configuration files of Apache Server which provide

  a way to make configuration changes on a per-directory basis. A file,
  containing one or more configuration directives, is placed in a particular
  document directory, and the directives apply to that directory, and all
  subdirectories thereof.

55. What is Joomla in PHP?

Joomla is a content management system. Powerful online applications and web sites are build using Joomla. Joomla is an open source CMS tool. Clients can easily manage their web sites with minimal amount of instructions. It is highly extensible. Joomla runs off PHP or MySQL. Joomla is used to create, maintain a structured, flexible portal, add or edit content, changes the look and feel of the site. PHP scripting is used and persisted most of its data / information in MySQL database.

56. What is meant by PEAR in php? What is the purpose of it?

PEAR stands for "PHP Extension and Application Repository". As the name suggests, it gives advanced functionality to the PHP language and include many applications which can be used on fly. The purpose of it is as follows:-

- Open source structured library for PHP users
- Code distribution and package maintenance system
- Standard style for code written in PHP

57. What is meant by urlencode and urldocode?

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

58. What is MIME?

MIME - Multi-purpose Internet Mail Extensions.

MIME types represents a standard way of classifying file types over Internet.
Web servers and browsers have a list of MIME types, which facilitates files transfer of the same type in the same way, irrespective of operating system they are working in. 
A MIME type has two parts: a type and a subtype. They are separated by a slash  (/).
MIME type for Microsoft Word files is application and the subtype is msword,
i.e. application/msword.

59. what is PDO ?

The PDO ( PHP Data Objects ) extension defines a lightweight,

  consistent interface for accessing databases in PHP. if you are using
  the PDO API, you could switch the database server you used, from
  say PgSQL to MySQL, and only need to make minor changes to your
  PHP code.
  While PDO has its advantages, such as a clean, simple, portable API
  but its main disadvantage is that it doesn't allow you to use all of
  the advanced features that are available in the latest versions of
  MySQL server. For example, PDO does not allow you to use MySQL's
  support for Multiple Statements.
  Just need to use below code for connect mysql using PDO
  try {
  $dbh = new

PDO("mysql:host=$hostname;dbname=databasename", $username,
  $sql = "SELECT * FROM employee";
  foreach ($dbh->query($sql) as $row)
  print $row['employee_name'] .' - '. $row['employee_age'] ;
  catch(PDOException $e)
  echo $e->getMessage();

60. What is PEAR in php?

PEAR(PHP Extension and Application Repository) is a framework and repository for reusable PHP components. PEAR is a code repository containing all kinds of php code snippets and libraries.

PEAR also offers a command-line interface that can be used to automatically install "packages".

61. What is PHP?

PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for web development. PHP scripts are executed on the server. PHP allows writing dynamically generated web pages efficiently and quickly. The syntax is mostly borrowed from C, Java and perl. PHP is free to download and use.

62. what is session_set_save_handler in PHP?

session_set_save_handler() sets the user-level session storage

  functions which are used for storing and retrieving data associated
  with a session. This is most useful when a storage method other
  than those supplied by PHP sessions is preferred. i.e. Storing the
  session data in a local database

63. What is the difference between $argv and $argc? Give example?

To pass the information into the script from outside, help can be taken from the PHP CLI (Command line interface) method. Suppose addition of two numbers has to be passed to PHP then it can be passed like this on the command line:

  php add.php 2 3
  Here the script name is add.php, and 2 and 3 are the numbers that has to be added by the script. These numbers are available inside the script in an array called $argv. This array contains all the information on the command line; the statement is stored as follows:
  So, $argv always contains at least one element '' the script name.
  Then, in your script, you can use the following statements:
  $sum = $argv[1] + $argv[2];
  echo $sum;
  $argc is a variable that stores the numbers of elements in $argv. $argc is equal to at least 1, which is saved for the name of the script. Example is $argc=3 using the above statements.

64. What is the difference between $message and $$message?    

The main difference between $message and $$message is that former one is a simple variable and later is a reference variable. $message is a variable with a fixed name and it consists of a fixed value. $$messages contains the variable itself.

65. What is the difference between $name and $$name?

$name is variable where as $$name is reference variable

  like $name=sonia and $$name=singh so $sonia value is singh.

66. What is the difference between echo and print statement in PHP?

Multiple expressions can be given in echo statement, where as print cannot take multiple expressions.

Echo does not have a return value, where as print returns a value indicating successful execution.
Echo is faster when compared with print.

67. What is the difference between echo, print and printf()?  

Echo is the basic type used to print out a string. It just shows the content of the message written using it. It can have multiple parameters as well. print is a construct, it returns TRUE on successful output and FALSE there is no output. It can't have multiple parameters. Printf() is a function, and not be used as a construct. It allows the string output to be formatted. It is the slowest medium to print the data out.

68. What is the difference between include and require in PHP?

The include() and require() are almost similar except the way they handle failures. include() produces a warning and require() produces a fatal error. To halt processing of the page, use require(). The same operation will not halt by using include(). It should be ensured that the include_path settings are proper. Both are used for inserting the file content into PHP file prior to its execution by the server.

69. What is the difference between mysql_fetch_object and mysql_fetch_array in PHP?

mysql_fetch_object: Results are objects returned from database. Fields are accessible like

$result->name, $result->cust_name, where $result is the result object and name, cust_name are the fields.
mysql_fetch_array : Results are arrays returned from database. Fields are accessible like $result[name], $result[cust_name].

70. What is the difference between mysql_fetch_object and mysql_fetch_array?

mysql_fetch_object() is similar tomysql_fetch_array(), with

  one difference -
  an object is returned, instead of an array. Indirectly, that means
  you can only access the data by the field names, and not by their
  offsets (numbers are illegal property names).

71. What is the difference between Notify URL and Return URL?

Notify URL and Return URL is used in Paypal Payment Gateway integration. Notify URL is used by PayPal to post information about the transaction. Return URL is sued by the browser; A url where the user needs to be redirected on completion of the payment process.

72. What is the difference between PHP and JavaScript?

The difference lies with the execution of the languages. PHP is server side scripting language, which means that it can't interact directly with the user. Whereas, JavaScript is client side scripting language, that is used to interact directly with the user..

73. What is the difference between Split and Explode in PHP?

The split() function splits the string into an array using a regular expression and returns an array.

Ex: split(:India:Pakistan:Srilanka); returns an array that contains India, Pakistan, Srilanka.

The explode() function splits the string by string.
Ex: explode(and India and Pakistan and Srilanka); returns an array that contains India, Pakistan, Srilanka.
74. What is the difference between the functions unlink and unset in PHP?
The function unlink() is to remove a file, where as unset() is used for destroying a variable that was declared earlier.
unset() empties a variable or contents of file.

75. What is the functionality of the function htmlentities?

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

76. What is the functionality of the function strstr and stristr?

strstr Returns part of string from the first occurrence of needle(sub

  string that we finding out ) to the end of string.
  $email= 'sonialouder@gmail.com';
  $domain = strstr($email, '@');
  echo $domain; // prints @gmail.com
  here @ is the needle
  stristr is case-insensitive means able not able to diffrenciate
  between a and A

77. What is the use of $_Server and $_Env?

$_SERVER and $_ENV arrays contain different information. The information depends on the server and operating system being used. Most of the information can be seen of an array for a particular server and operating system. The syntax is as follows:
  foreach($_SERVER as $key =>$value)
  { echo ''Key=$key, Value=$value\n''; }

78. What is the use of PEAR in php?

PEAR is known as PHP Extension and Application Repository. It provides structured library to the PHP users and also gives provision for package maintenance.

79. What is the use of super-global arrays in PHP?

Super global arrays are the built in arrays that can be used anywhere. They are also called as auto-global as they can be used inside a function as well. The arrays with the longs names such as $HTTP_SERVER_VARS, must be made global before they can be used in an array. This $HTTP_SERVER_VARS check your php.ini setting for long arrays.

80. What is Type juggle in php?

In order to declare a variable in PHP, the type of the variable is not required. The data type is determined by the value / context of the variable. If integer value is assigned to the variable $num, then the variable $num is of the type integer. If string value is assigned to the variable $str, the variable $str is of the type string.

81. What is urlencode and urldecode in PHP?

urlencode () is the function that can be used conveniently to encode a string before using in a query part of a URL. This is a convenient way for passing variables to the next page.

urldecode() is the function that is used to decode the encoded string.

82. What is use of header() function in php ?

The header() function sends a raw HTTP header to a client.We can

  use herder()
  function for redirection of pages. It is important to notice that
  header() must
  be called before any actual output is seen..

83. What is zend engine in PHP?

Zend engine is like a virtual machine and is an open source, and is known for its role in automating the web using PHP. Zend is named after its developers Zeev and Aandi. Its reliability, performance and extensibility has a significant role in increasing the PHP's popularity. The Zend Engine II is the heart of PHP 5. It is an open source project and freely available under BSD style license.

84. What type of inheritance that PHP supports?

In PHP an extended class is always dependent on a single base

  that is, multiple inheritance is not supported. Classes are extended
  using the keyword 'extends'.

85. What's the difference between COPY OF A FILE & MOVE_UPLOAD_FILE in file uploading?

Move: This function checks to ensure that the file designated by filename is a valid upload file (meaning that it

  was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename
  given by destination.
  If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
  Copy: Makes a copy of a file. Returns TRUE if the copy succeeded, FALSE otherwise

86. Why IDE is recommended for use while programming with PHP?    

IDE stands for Integrated Development environment; it is a framework for developing applications. It includes programming editor where you can edit and write the development programs. The features of IDE are as follows:
  1. Debugging: this is the feature which is used to debug or find the bugs in a program
  2. Preview: this is the feature which allow instant preview of the program you are writing
  3. Testing: this is the features that includes built in testing features through which you can check your scripts
  4. FTP: through this you can upload and download the file while connecting to the server.
  5. Project management: it organizes scripts into projects; manages the files in the project; includes file checkout and check-in features.
  6. Backups: it creates backups automatically of your Web site at periodic intervals.

87. Why many companies are switching their current business language to PHP? Where PHP basically used?

PHP is rapidly gaining the popularity and many companies are switching their current language for this language. PHP is a server side scripting language. PHP executes the instructions on the server itself. Server is a computer where the web site is located. PHP is used to create dynamic pages and provides faster execution of the instructions.

88. Why PHP is also called as Scripting language?

PHP is basically a general purpose language, which is used to write scripts. Scripts are normal computer files that consist of instructions written in PHP language. It tells the computer to execute the file and print the output on the screen. PHP is used for webpages and to create websites, thus included as scripting language.

89. Why PHP is sometimes called as embedded scripting language?

PHP is a high level language which is used to allow users to write and understand it in human readable form and also use an interpreter to interpret the code which user write for the computer. PHP is used as an embedded scripting language for the web. PHP is embedded in HTML code. HTML tags are used to enclose the PHP language. HTML is used and PHP is code written in it in the same way as you write JavaScript in HTML.

90. Write a Hello world program using variable?   

To write the hello world program in PHP using variable you need to know the tags that are used in HTML and the PHP coding which is as follows:
  <head><title>Hello World Script using Variable</title></head>
  $salutation = ''Hello World!'';
  echo ''<p>$salutation</p>'';

91. Write a program to show the joining of two strings in PHP?

Two strings can be joined together by the use of a process called as concatenation. A dot (.) operator is used for this purpose. Example is as follows:

  $string1 = _Hello_;
  $string2 = _World!_;
  $stringall = $string1.$string2;
  echo $stringall;

92. Write a statement to show the joining of multiple comparisons in PHP?

PHP allows multiple comparisons to be grouped together to determine the condition of the statement. It can be done by using the following syntax:

  comparison1 and|or|xor comparison2 and|or|xor comparison3 and|or|xor.
  The operators that are used with comparisons are as follows:
  1. and: result in positive when both comparisons are true.
  2. or: result in positive when one of the comparisons or both of the comparisons are true.
  3. xor: result in positive when one of the comparisons is true but not both of the comparisons.
  $resCity == ''Reno'' or $resState == ''NV'' and $name == ''Sally''

93. Write the statements that are used to connect PHP with MySQL

The statements that can be used to connect PHP wil MySQL is:

$conn = mysql_connect('localhost');
echo $conn;
This statement gets the resource of the localhost. There are other different ways with which you can connect to the database and they are as follows:

No comments:

Post a Comment