PHP Top 100 interview questions answers

PHP AND MySQL Technical Interview Questions and Answers for Freshers and Experienced:i had Attended more interviews and face some Regular Questions.These are as seen below...
Php Interview Questions
1)What is PHP?

PHP: Hypertext Preprocessor: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.

2)How a constant is defined in a PHP script?

Constants are defined by using the define()directive.PHP constant() is useful if you need to retrieve the value of a constant. PHP Constant value cannot change during the execution of the code. By default constant is case-sensitive

<html>
<head>
<title>My First php Constant Program</title>
</head>
<body>
<?php
define(“numbers”, 1234);
define(“TEXT”, “php”);
echo constant (“numbers”);
echo constant (“TEXT”);
?>
</body>
</html>

output: 1234php

3)What are the Difference Between strstr() and stristr()?

This strstr() function is used to return the character from a string from specified position

Example:

<html>
<head>
<title>My First String strstr Program</title>
</head>
<body>
<?php
$str=”welcome to php”;
echo strstr($str,’t');
?>
</body>
</html>

Output: to php
stristr()function

This function is same as strstr is used to return the character from a string from specified position,But it is CASE INSENSITIVE

Example:

<html>
<head>
<title>My First String strIstr Program</title>
</head>
<body>
<?php
$str=”WELCOME TO PHP”;
echo stristr($str,’t');
?>
</body>
</html>

output:TO PHP

4)Differences between Get and post methods in PHP?

GET and POST methods are used to send data to the server, both are used to same purpose .But both are some defferences

GET Method have send limit data like only 2Kb data able to send for request and data show in url,it is not safety.

POST method unlimited data can we send for request and data not show in url,so POST method is good for send sensetive request.

5)How do I find out the number of parameters passed into function. ?

func_num_args() function returns the number of parameters passed in.

6)What is 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.
urlencode Example program:
<?php
$arr=urlencode(“20.00%”);
echo $arr;
?>

Here urlencode(“20.00%”) will return “20.00%25. URL encoded strings are safe to be used as part of URLs.

urldecode() returns the URL decoded version of the given string.

urldecode Example Program:

<?php
$arr=urldecode(“20.00%”);
echo $arr;
?>

output:20.00%

7)How to increase the execution time of a php script?

To Change max_execution_time variable in php.ini file .By Default time is 30 seconds
The file path is xampp/php/php.ini

8)Difference between htmlentities() and htmlspecialchars()?

htmlentities() – Convert ALL special characters to HTML entities

htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used)

9)What is the difference between $message and $$message?

$message is a simple variable whereas $$message is a reference variable.

Example:

<?php
$message = “php”;
$php= “cms”;
echo $message;
echo ‘<br>’;
echo $$message;
?>

Output:

php
cms

10)How To Get the Uploaded File Information in the Receiving Script?


Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES.

$_FILES[$fieldName]['name'] – The Original file name on the browser system.
$_FILES[$fieldName]['type'] – The file type determined by the browser.
$_FILES[$fieldName]['size'] – The Number of bytes of the file content.
$_FILES[$fieldName]['error'] – The error code associated with this file upload.
$_FILES[$fieldName]['tmp_name'] – The temporary filename of the file in which the uploaded file was stored on the server.

11)What is difference between Array combine() and Array merge()?

Array_combine(): To Combines the elements of two arrays and Returns the New Array.The new Array keys are the values of First Array values and the new array values are Second array values.

Array_combine()Example:

<?php
$arr=array(10,30,50);
$arr1=array(45,67,54);
print_r(array_combine($arr,$arr1));
?>

Output:

Array
(
[10] => 45
[30] => 67
[50] => 54
)
Array_merge(): merges two or more Arrays as New Array.

Array_merge() Example:

<?php
$arr=array(10,30,50);
$arr1=array(45,67,54);
print_r(array_merge($arr,$arr1));
?>

output:

Array
(
[0] => 10
[1] => 30
[2] => 50
[3] => 45
[4] => 67
[5] => 54
)

12)What is Implode() Function in PHP?

The implode function is used to “join elements of an array with a string”.

Example:

<?php
$arr=array (“open”,”source”,”cms”);
echo implode(” “,$arr);
?>

Output: open source cms

13)what Explode() Function in PHP?

The explode function is used to “Split a string by a specified string into pieces i.e. it breaks a string into an array”.

Example:

<?php
$str = “Gampa venkateswararao vaidana ballikurava “;
print_r (explode(” “,$str));
?>

output:

Array
(
[0] => Gampa
[1] => venkateswararao
[2] => vaidana
[3] => ballikurava
[4] =>
)

14)What does a special set of tags do in PHP?

in PHP special tags <?= and ?> the use of this Tags are The output is displayed directly to the browser.

15)What is the difference between md5(),crc32() and sha1() in PHP?

All of these functions generate hashcode from passed string argument.

The major difference is the length of the hash generated

crc32() gives 32 bit code

sha1() gives 128 bit code

md5() gives 160 bit code

16)What are the differences between require() and include()?

Both include() and require() used to include a file ,if the code from a file has already have included,it will not be included again. we have to use this code multiple times .But both are some minor Difference Include() send a Warning message and Script execution will continue ,But Require() send Fatal Error and to stop the execution of the script.

17)What are the differences between require_once(), include_once?

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.

18)What is session in php?

session variable is used to store the information about a user and the information is available in all the pages of one application and it is stored on the server.

An user sends the first Request to the Server for every new user webserver creates an Unique ID The Request is called as Session_id.Session_id is an unique value generated by the webserver. To start a session by using session_start()

Starting a PHP Session

Example:

<?php
// this starts the session
session_start();
// this sets variables in the session
$_SESSION['Name']=’Venki’;
$_SESSION['Qulification']=’MCA’;
$_SESSION['Age']=27;
?>
Add or access session variables by using the $_SESSION superglobal array.

How to Retrive Data?

<?php
session_start();
echo “Name = ” $_SESSION["Name"];// retrieve session data
?>

To delete a single session value, you use the unset() function:

<?php
session_start();
unset($_SESSION["Name"]);
?>
How to Destroy the Session?

<?php
session_start();
session_destroy();// terminate the session
?>

19)What is the default session time in php?

The default session time in php is until closing of browser

20)What is Cookie and How to Create a Cookie in php?


Cookie is a piece of information that are stored in the user Browser memory, usually in a temporary folder. Cookies can be useful as they store persistent data you can access from different pages of your Website, but at the same data they are not as secure as data saved in a server
in PHP, you can both create and retrieve cookie values.

How to Create a Cookie?

using The setcookie() function is used to set a cookie.

Syntax

setcookie(name, value, expire, path, domain);
Example

<?php
setcookie(“user”, “venki”, time()+3600);
?>
How to a retrieve a cookie value?

$_COOKIE variable is used to retrieve a cookie value.

Example:

<?php
echo $_COOKIE["user"];// Print a cookie
print_r($_COOKIE); // view all cookies
?>

How to Accessing a cookie?

In the following example we use the isset() function to find out if a cookie has been set:
<?php

if( isset($_COOKIE['username']) ) //storing the value of the username cookie into a variable
{
$username = $_COOKIE['username'];
}
?>

21)How can you destroy or Delete a Cookie?

Destroy a cookie by specifying expire time in the past:

Example: setcookie(’opensource’,’php’,time()-3600); // already expired time

22)Difference between Persistent Cookie and Temporary 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.

23)Difference Between Cookies and Sessions in php?

Cookies and sessions both are used to store values or data,But there are some differences a cookie stores the data in your browser memory and a session is stored on the server.

Cookie data is available in your browser up to expiration date and session data available for the browser run, after closing the browser we will lose the session information.

Cookies can only store string data,but session stored any type of data.we could be save cookie for future reference, but session couldn’t. When users close their browser, they also lost the session.
Cookies are unsecured,but sessions are highly Secured.
You lose all the session data once you close your browser, as every time you re-open your browser, a new session starts for any website.

Cookies stores some information like the username, last visited Web pages etc. So that when the customer visits the same site again, he may have the same environment set for him. You can store almost anything in a browser cookie.when you check the ‘Remember Password’ link on any website, a cookie is set in your browser memory, which exists there in the browser until manually deleted. So, when you visit the same website again, you don’t have to re-login.

The trouble is that a user can block cookies or delete them at any time. If, for example, your website’s shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.

24)How to connet mysql database with PHP ?

$con = mysql_connect(“localhost”, “username”, “password”);

Example:

<?php

if($con=mysql_connect(“localhost”,”root”,”"))
echo “connected”;
else
echo “not connected”;
if(mysql_query(“create Database emp”,$con))
echo “Database Created”;
else
echo “Database not Created”;
?>

output:

connectedDatabase Created

25)What is the function mysql_pconnect() usefull for?

mysql_pconnect() ensure a persistent connection to the database, it means that the connection do not close when the the PHP script ends.

26)Different Types of Tables in Mysql?

There are Five Types Tables in Mysql

1)INNODB
2)MYISAM
3)MERGE
4)HEAP
5)ISAM

27)What is the Difference between INNODB and MYISAM?

The main difference between MyISAM and InnoDB is that InnoDB supports transaction
InnoDB supports some newer features: Transactions, row-level locking, foreign keys

MYISAM:
1. MYISAM supports Table-level Locking
2. MyISAM designed for need of speed
3. MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS
4. MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
5. MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.

INNODB:
1. InnoDB supports Row-level Locking
2. InnoDB designed for maximum performance when processing high volume of data
3. InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS
4. InnoDB stores its tables and indexes in a tablespace
5. InnoDB supports transaction. You can commit and rollback with InnoDB

28) What is the difference between mysql_fetch_object() and mysql_fetch_array()?

The mysql_fetch_object() function collects the first single matching record

mysql_fetch_array() collects all matching records from the table in an array.

28)How many ways we can retrieve the date in result set of mysql using php?

The result set can be handled using 4 ways

1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc

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

30)What is the maximum length of a table name, a database name, or a field name in MySQL?

Database name: 64 characters
Table name: 64 characters
Column name: 64 characters

31)What is the difference between CHAR and VARCHAR data types?

CHAR is a fixed length data type. CHAR(n) will take n characters of storage even if you enter less than n characters to that column.

VARCHAR is a variable length data type. VARCHAR(n) will take only the required storage for the actual number of characters entered to that column.

32)How can we know that a session is started or not?

A session starts by using session_start() function.

33)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?

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

34)Who is the father of php and explain the changes in php versions?

Rasmus Lerdorf for version changes go to http://php.net/ Marco Tabini is the founder and publisher of php|architect.

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

36)How many ways we can retrieve the date in result set of mysql Using php?

As individual objects so single record or as a set or arrays.

37)What is the difference between $message and $$message?

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.

38)What are the differences between require and include, 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(). This will prevent problems with function redefinitions, variable value reassignments, etc.

39)What are the different tables present in mysql?

Total 5 types of tables we can create 

1. MyISAM 

2. Heap 

3. Merge 

4. InnoDB 

5. ISAM 

6. BDB 

MyISAM is the default storage engine as of MySQL 3.23.

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

41)What is meant by nl2br()?

Nl2br Inserts HTML line breaks before all newlines in a string string nl2br (string); For example: echo nl2br("god bless you")

will output "god bless you" to your browser.

42)What are the current versions of apache, php, and mysql?

PHP: php 5.3 
MySQL: MySQL 5.5 
Apache: Apache 2.2

43)What are the reasons for selecting lamp (Linux, apache, mysql, php) instead of combination of other software programs, servers and operating systems?


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.

44)How can we encrypt and decrypt a data present in a mysql table using mysql?

AES_ENCRYPT () and AES_DECRYPT ()

45)How can we encrypt the username and password using php?

You can encrypt a password with the following Mysql>SET PASSWORD=PASSWORD("Password"); We can encode data using base64_encode($string) and can decode using base64_decode($string);

46)What are the different types of errors in php?

E_ERROR: A fatal error that causes script termination 
E_WARNING: Run-time warning that does not cause script termination 
E_PARSE: Compile time parse error. 
E_NOTICE: Run time notice caused due to error in code 
E_CORE_ERROR: Fatal errors that occur during PHP's initial startup (installation) 
E_CORE_WARNING: Warnings that occur during PHP's initial startup 
E_COMPILE_ERROR: Fatal compile-time errors indication problem with script. 
E_USER_ERROR: User-generated error message. 
E_USER_WARNING: User-generated warning message. 
E_USER_NOTICE: User-generated notice message. 
E_STRICT: Run-time notices. 
E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error 
E_ALL: Catches all errors and warnings

47)What is the functionality of the function htmlentities?

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

48)What is meant by urlencode and urldocode?

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.

49)What is the difference between the functions unlink and unset?

Unlink() deletes the given file from the file system. 
unset() makes a variable undefined.

50)How can we register the variables into a session?


We can use the session_register ($ur_session_var) function.

51)How can we get the properties (size, type, width, height) of an image using php image functions?

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

52)What is the maximum size of a file that can be uploaded using php and how can we change this?

You can change maximum size of a file set upload_max_filesize variable in php.ini file.

53)How can we increase the execution time of a php script?

Set max_execution_time variable in php.ini file to your desired time in second.

54)How can we take a backup of a mysql table and how can we restore it.?


Create a full backup of your database: shell> mysqldump tab=/path/to/some/diropt db_name Or: shell> mysqlhotcopy db_name /path/to/some/dir The full backup file is just a set of SQL statements, so restoring it is very easy: 

shell> mysql "."Executed"; 
mysql_close($link2);

55)How many ways can we get the value of current session id?

session_id() function returns the session id for the current session.

56)How can we destroy the session, how can we unset the variable of a session?

session_destroy
session_unset

57)How can we destroy the cookie?

Set same the cookie in past

58)What is the difference between ereg_replace() and eregi_replace()?

eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.eregi_replace() function is identical to ereg_replace() except that this ignores case distinction when matching alphabetic characters.

59)How can we know the count/number of elements of an array?

2 ways 
a) sizeof($urarray) This function is an alias of count() 
b) count($urarray)
interestingly if u just pass a simple var instead of a an array it will return 1.

60)What is the maximum length of a table name, database name, and fieldname in mysql?

Database name- 64 
Table name -64 Fieldname-64

61)How many values can the SET function of mysql takes?

Mysql set can take zero or more values but at the maximum it can take 64 values

62)What is maximum size of a database in mysql?

If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint. 
The efficiency of the operating system in handling large numbers of files in a directory can place a practical limit on the number of tables in a database. If the time required to open a file in the directory increases significantly as the number of files increases, database performance can be adversely affected. 
The amount of available disk space limits the number of tables. 
MySQL 3.22 had a 4GB (4 gigabyte) limit on table size. With the MyISAM storage engine in MySQL 3.23, the maximum table size was increased to 65536 terabytes (2567 รข€" 1 bytes). With this larger allowed table size, the maximum effective table size for MySQL databases is usually determined by operating system constraints on file sizes, not by MySQL internal limits. 
The InnoDB storage engine maintains InnoDB tables within a tablespace that can be created from several files. This allows a table to exceed the maximum individual file size. The tablespace can include raw disk partitions, which allows extremely large tables. The maximum tablespace size is 64TB. 
The following table lists some examples of operating system file-size limits. This is only a rough guide and is not intended to be definitive. For the most up-to-date information, be sure to check the documentation specific to your operating system. 
Operating System File-size Limit 
Linux 2.2-Intel 32-bit 2GB (LFS: 4GB) 
Linux 2.4+ (using ext3 filesystem) 4TB 
Solaris 9/10 16TB 
NetWare w/NSS filesystem 8TB 
Win32 w/ FAT/FAT32 2GB/4GB 
Win32 w/ NTFS 2TB (possibly larger) 
MacOS X w/ HFS+ 2TB

63)What is meant by MIME?

Multipurpose Internet Mail Extensions.
WWW ability to recognise and handle files of different types is largely dependent on the use of the MIME (Multipurpose Internet Mail Extensions) standard. The standard provides for a system of registration of file types with information about the applications needed to process them. This information is incorporated into Web server and browser software, and enables the automatic recognition and display of registered file types.

64)What is meant by PEAR in php?

PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide: 
A structured library of open-sourced code for PHP users 
A system for code distribution and package maintenance 
A standard style for code written in PHP 
The PHP Foundation Classes (PFC), 
The PHP Extension Community Library (PECL), 
A web site, mailing lists and download mirrors to support the PHP/PEAR community 
PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then. 

65)What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

Mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both. 
mysql_fetch_object ( resource result ) 
Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows 
mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

66)What is the difference between include and require?

If you require a file and it cannot be found, the script will terminate with a fatal error. If you use include then you will get an error but the script will continue to execute. Therefore when the information you wish to reference from another file is essential to the correct running of a page, use require.

67)Is PHP a case sensitive programming language?

PHP is a partially case sensitive programming language. We can use function names, class names in case insensitive manner.

68)What is mean by LAMP?

LAMP means combination of Linux, Apache, MySQL and PHP.

69)How do you get the user's ip address in PHP?

Using the server variable: $_SERVER['REMOTE_ADDR']

70)How do you make one way encryption for your passwords in PHP?

Using md5 function or sha1 function

71)What is meant by PEAR in php?

Answer1: PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install "packages" 

Answer2: 
PEAR is short for "PHP Extension and Application Repository" and is pronounced just like the fruit. The purpose of PEAR is to provide: 
A structured library of open-sourced code for PHP users 
A system for code distribution and package maintenance 
A standard style for code written in PHP 
The PHP Foundation Classes (PFC), 
The PHP Extension Community Library (PECL), 
A web site, mailing lists and download mirrors to support the PHP/PEAR community 
PEAR is a community-driven project with the PEAR Group as the governing body. The project has been founded by Stig S. Bakken in 1999 and quite a lot of people have joined the project since then.

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

73)What is the difference between echo and print statement?

Echo() can take multiple expressions,Print cannot take multiple expressions. 

Print return true or false based on success or failure whereas echo just does what its told without letting you know whether or not it worked properly.

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

75)What is the value of $b in the following code?
    $a="5 USD";
    $b=10+$a;
    echo $b;
?>

Ans:15

76)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?

In the get method the data made available to the action page ( where data is received ) by the URL so data can be seen in the address bar. Not advisable if you are sending login info like password etc.

In the post method the data will be available as data blocks and not as query string. 

77)What is GPC?

G – Get
P – Post
C – Cookies

78)What are super global arrays?

All variables that come into PHP arrive inside one of several special arrays known collectively as the superglobals. They're called superglobal because they are available everywhere in your script, even inside classes and functions.
5:Give some example for super global arrays?
$GLOBALS
$_GET
$_POST
$_SESSION
$_COOKIE
$_REQUEST
$_ENV
$_SERVER

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

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

80)When I do the following, the output is printed in the wrong order:

function myfunc($argument) {
        echo $argument + 10;
      }
      $variable = 10;
 echo "myfunc($variable) = " . myfunc($variable);

What's going on?
To be able to use the results of your function in an expression (such as concatenating it with other strings in the example above), you need to return the 
value, not echo it.

81)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

82)Explain the types of string comparision function in PHP.
     
      Function              Descriptions
strcmp()             :Compares two strings (case sensitive)
strcasecmp()      :Compares two strings (not case sensitive)
strnatcmp(str1, str2) :Compares two strings in ASCII order, but
                                    any numbers are compared numerically
strnatcasecmp(str1, str2):Compares two strings in ASCII order, 
                                          case insensitive, numbers as numbers
strncasecomp()  : Compares two strings (not case sensitive) 
                            and allows you to specify how many characters
                             to compare
strspn()             : Compares a string against characters represented
                             by a mask
strcspn()           : Compares a string that contains characters not in
                            the mask

83)Explain soundex() and metaphone().

soundex():
The soundex() function calculates the soundex key of a string. A soundex key is a four character long alphanumeric string that represent English pronunciation of a word. he soundex() function can be used for spelling applications.
$str = "hello";
echo soundex($str);
?>
metaphone():
The metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if said by an English speaking person. The metaphone() function can be used for spelling applications.
echo metaphone("world");
?>

84)What do you mean range()?

Starting from a low value and going to a high value, the range() function creates an array of consecutive integer or character values. It takes up to three arguments: a starting value, an ending value, and an increment value. If only two arguments are given, the increment value defaults to 1.
Example :
echo range(1,10); // Returns 1,2,3,4,5,6,7,8,9,10
?>

85)How to read and display a HTML source from the website url?

$filename="http://www.kaptivate.in/";
$fh=fopen("$filename", "r");
while( !feof($fh) ){
$contents=htmlspecialchars(fgets($fh, 1024));
print "
$contents
";
}
fclose($fh);
?>

86)What is properties of class?

Class member variables are called "properties". We may also see them referred to using other terms such as "attributes" or "fields", but for the purposes of this reference we will use "properties". They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

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

88)Why we used PHP?

Because of several main reason we have to use PHP. These are:
1.PHP runs on many different platforms like that Unix,Linux and Windows etc.
2.It codes and software are free and easy to download.
3.It is secure because user can only aware about output doesn't know how that comes.
4.It is fast,flexible and reliable.
5.It supports many servers like: Apache,IIS etc.

89)Arrays  in PHP?

Create array in PHP to solved out the problem of writing same variable name many time.In this we create a array of variable name and enter the similar variables in terms of element.Each element in array has a unique key.Using that key we can easily access the wanted element.Arrays are essential for storing, managing and operating on sets of variables effectively. Array are of three types:
1.Numeric array 
2.Associative array
3.Multidimensional array 
 Numeric array is used to create an array with a unique key.Associative array is used to create an array where each unique key is associated with their value.Multidimensional array is used when we declare multiple arrays in an array.

90)What is foreach loop in  php?

foreach:Uses, When When we want execute a block of code for each element in an array.
Syntax:
foreach (array as value)
{
    code will be executed;
}
eg:
$arr=array("one", "two", "three");
foreach ($arr as $value)
{
  echo "Value: " . $value . "
";
}
?> 

91)How we used $_get and $_post variable in PHP?

We know that when we use $_GET variable all data_values are display on our URL.So,using this we don't have to send secret data (Like:password, account code).But using we can bookmarked the importpage.
 We use $_POST variable when we want to send data_values without display on URL.And their is no limit to send particular amount of character.
Using this we can not bookmarked the page.

92)Why we use $_REQUEST variable?

We use $_REQUEST variable in PHP to collect the data_values from $_GET,$_POST and $_COOKIE variable.
Example:
R4R Welcomes You .

You are years old! 

93)How we handle errors in PHP?Explain it?

In PHP we can handle errors easily.Because when error comes it gives error line with their respective line and send error message to the web browser.
When we creating any web application and scripts. We should handle errors wisely.Because when this not handle properly it can make bg hole in security.
In PHP we handle errors by using these methods:
1.Simple "die()" statements
2.Custom errors and error triggers
3.Error reporting

94)How we use Custom errors and error triggers error handling method in PHP?

In Custom errors and error triggers,we handle errors by 
using self made functions.
1.Custom errors : By using this can handle the multiple 
errors that gives multiple message.
Syntax:
set_error_handler(\\\"Custom_Error\\\"); 
In this syntax if we want that our error handle, handle
only one error than we write only one argument otherwise
for handle multiple errors we can write multiple arguments.

Example:
//function made to handle errorfunction 
custom_Error($errorno, $errorstr)  
{   
   echo \\\"Error: [$errorno] $errorstr\\\";  }
//set error handler like that
set_error_handler(\\\"custom_Error\\\");
//trigger to that error
echo($verify);?>

2.error trigger : In PHP we use error trigger to handle
those kind of error when user enter some input data.If 
data has an error than handle by error trigger function.
Syntax:

$i=0;if ($i<=1)
{
trigger_error(\\\"I should be greater than 1 \\\");
}
?> 
In this trigger_error function generate error when i is
less than or greater than 1.

95)What do you understand about Exception Handling in PHP?

In PHP 5 we introduce a Exception handle to handle run time exception.It is used to change the normal flow of the code execution if a specified error condition occurs.
An exception can be thrown, and caught("catched") within PHP. Write code in try block,Each try must have at least one catch block. Multiple catch blocks can be used to catch different classes of exceptions. 
Some error handler methods given below:
1.Basic use of Exceptions
2.Creating a custom exception handler
3.Multiple exceptions
4.Re-throwing an exception
5.Setting a top level exception handler

96)What is the difference b/n 'action' and 'target' in form tag?


Action: 
    Action attribute specifies where to send the form-data when
a form is submitted.
    Syntax: 
    Example: 
action="formValidation.php">
Target:
    The target attribute specifies where to open the action URL.
     Syntax: 
        Value:
         _blank – open in new window
        _self- Open in the same frame as it was clicked
        _parent- Open in the parent frameset
        _top- Open in the full body of the window
        Framename- Open in a named frame

97)How we use ceil() and floor() function in PHP?

ceil() is use to find nearest maximum values of passing value.
Example:
$var=6.5;
$ans_var=ceil($var);
echo $ans_var;
Output:
7
floor() is use to find nearest minimum values of passing value.
Example:
$var=6.5
$ans_var=floor($var);
echo $ans_var;  
Output:
6

98)What is the answer of following code

echo 1< 2 and echo 1 >2 ?

Output of the given code are given below:
echo 1<2
output: 1
echo 1>2
output: no output
99)What is the difference b/w isset and empty? 
The main difference b/w isset and empty are given below:
isset: This variable is used to handle functions and checked a variable is set even through it is empty.
empty: This variable is used to handle functions and checked either variable has a value or it is an empty string,zero0 or not set at all.

100)What do you understand about PHP accelerator ? 

Basically PHP accelerator is used to boost up the performance of PHP programing language.We use PHP accelerator to reduce the server load and also use to enhance the performance of PHP code near about 2-10 times.In one word we can say that PHP accelertator is code optimization technique. 

No comments:

Post a Comment