Wednesday, 17 February 2016

PHP interview questions



-What is PHP?
Ans. PHP is a recursive acronym for "PHP: Hypertext Preprocessor". PHP is a server side scripting language that is embedded in HTML. It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites.

-In how many ways you can embed PHP code in an HTML page?
Ans. All PHP code must be included inside one of the three special markup tags ate are recognised by the PHP Parser.
<?php PHP code goes here ?>
<?    PHP code goes here ?>
<script language="php"> PHP code goes here </script>
Most common tag is the <?php...?>

-Is PHP a case sensitive language?
Ans. Yes!

-types of PHP variables?
Ans. 
   Integers − are whole numbers, without a decimal point, like 4195. 
   Doubles − are floating-point numbers, like 3.14159 or 49.1. 
   Booleans − have only two possible values either true or false. 
   NULL − is a special type that only has one value: NULL. 
   Strings − are sequences of characters, like 'PHP supports string operations.' 
   Arrays − are named and indexed collections of other values. 
   Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class. 
   Resources − are special variables that hold references to resources external to PHP (such as database connections).

-What is NULL?
Ans. NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it like this −$my_var = NULL;
The special constant NULL is capitalized by convention, but actually it is case insensitive; you could just as well have typed −$my_var = null;
A variable that has been assigned NULL has the following properties:It evaluates to FALSE in a Boolean context.It returns FALSE when tested with IsSet() function.

-What is the purpose of _CLASS_ constant?
Ans. _CLASS_ − The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.

-How will you find the length of a string in PHP?
Ans. <?php echo strlen("Hello world!"); ?>
 
-What is the difference between include() Function and require() Function?
Ans. If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script whereas include() function generates a warning but the script will continue execution.
 
-How will you read a file in php?
Ans. Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.
 
-How will you set cookies using PHP?
Ans. PHP provided setcookie() function to set a cookie. This function requires upto six arguments and should be called before <html> tag. For each cookie this function has to be called separately.
setcookie(name, value, expire, path, domain, security);
 
-What does PEAR stands for?
Ans. PEAR means “PHP Extension and Application Repository”. it extends PHP and provides a higher level of programming for web developers.
 
-How do you execute a PHP script from the command line?
Ans. ust use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows: “php script.php”
 
-What is the difference between Session and Cookie?
Ans. The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user’s computers in the text file format. Cookies can not hold multiple variables,But Session can hold multiple variables.We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking.
 
-What is the use of explode() function ?
Ans. Syntax : array explode ( string $delimiter , string $string [, int $limit ] ); 

This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.
 
-What is the difference between explode() and split() functions?
Ans. Split function splits string into array by regular expression. Explode splits a string into array by string.
 
-What is the use of mysql_real_escape_string() function?
Ans. It is used to escapes special characters in a string for use in an SQL statement.
 
-What is the difference between mysql_fetch_array() and mysql_fetch_assoc() ?
Ans. 
mysql_fetch_assoc function Fetch a result row as an associative array, While 
mysql_fetch_array() fetches an associative array, a numeric array, or both
 
-How do you define a constant?
Ans. Using define() directive, like define ("MYCONSTANT",150)
 
-How send email using php?
Ans. mail($to,$subject,$message,$headers);
 
-What are the encryption techniques in PHP ?
Ans. 
MD5 PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg); 
mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] ); 
Encrypts plaintext with given parameters 
 
-How to delete a file from the system?
Ans. Unlink() deletes the given file from the file system.
 
-What is the use of the function htmlentities?
Ans. 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.

No comments:

Post a Comment

about new GraphQL freature in Magento2

GraphQL: GraphQL is a data query language developed internally by Facebook in 2012 before being publicly released in 2015. Magento impleme...