Showing posts with label Interview questions with answers. Show all posts
Showing posts with label Interview questions with answers. Show all posts

Tuesday, September 2, 2008

Interview Questions in PHP

1. How can we repair a MySQL table?

The syntex for repairing a mysql table is:

- REPAIR TABLE tablename -> This command will repair the table specified.
- REPAIR TABLE tablename QUICK -> If QUICK is given, MySQL will do a repair of only the index tree.
- REPAIR TABLE tablename EXTENDED -> If EXTENDED is given, it will create index row by row.

2. What's diffrence between Get() and Post() Function?

- Get shows information travling on the address bar
- but Post do not shows on the address bar
- the post method is more secure than get method

3. Which is the Best plateform for PHP?
LAMP Linux apache Mysql Php Because In Linux provides basic OS and server Environment In built Mysql no need to download

4. What is meant by urlencode and urldocode?
- urlencode -- URL-encodes string
- urldecode -- Decodes URL-encoded string

5. What is the functionality of the function strstr and stristr?
- strstr -- Find first occurrence of a string
- Example :
$email = 'user@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com
?>
- stristr -- Case-insensitive strstr()
- Example :
$email = 'USER@EXAMPLE.com';
$domain = stristr($email, 'e');
echo $domain;
// outputs ER@EXAMPLE.com
?>

6. What is meant by nl2br()?
- nl2br -- Inserts HTML line breaks before all newlines in a string
- Example :
echo nl2br("foo isn't\n bar");
/*output :
foo isn't

bar
*/
?>

7. How can we submit a form without a submit button?
- we can use the input type as 'image'
- i.e. < input type="image" src="submit.gif">

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

- getimagesize -- Get the size of an image
- Returns an array with 4 elements.
- Index 0 contains the width of the image in pixels.
- Index 1 contains the height.
- Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.
- Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
- Example:

list($width, $height, $type, $attr) = getimagesize("reset.jpg");
echo "

Width : ".$width;
echo "
Height : ".$height;
echo "
Type : ".$type;
echo "
Attribute : ".$attr;

/* Output :

Width : 53
Height : 22
Type : 2
Attribute : width="53" height="22"

*/
?>

9. How I will check that user is logged in or not?
- we can use session for this, at the time of login process we must store the user information into the session, and at the time of
logout we can destroy the session. by this way is the session value is set i.e. not equal to blank then we can easily identify
that user is logged in or not.
- Example:
if (isset($_SESSION['username']) && $_SESSION['username'] != ""){
echo "User already logged in";
} else {
echo "User not logged in";
}
?>

10. How I can get IP address of the usr?
- $_SERVER['REMOTE_ADDR']

11. Explain about the installation of PHP on UNIX systems?
PHP can be installed on UNIX in many different ways there are pre defined packages available which can ease the process. Initially it can be controlled by the command line options. Help can be obtained from./configure help command. After installing PHP modules or executables can be configures and make command should help you in the process.

12. How to enable parsing?
Parsing is an important concept if you want to run your code appropriately and timely. PHP parses all the code present between the opening and closing tags, it ignores everything present out of the closing and opening tags. This tags allow PHP to be embedded between many documents.

13. Explain about null?
Null represents a variable with no value inside. There doesn’t exist any value for type Null. Null is defined to be null if and only if it is assigned a constant null, there is no value set, it is set to be unset(). This is the case insensitive keyword. There are also two functions they are is_null and unset().

14. Explain about PHP looping?
Looping statements are used in PHP to execute the code for a developer defined number of times.
PHP has these following looping statements they are
- while() loop,
- do while() loop,
- for() loop and
- for each() loop .

Foreach is used to loop a block of code in each element in an array.

15. Explain about the advantages of using PHP?
There are many advantages of PHP they are
1) Easy and fast creation of dynamic web pages and a developer can also embed these dynamic functions into HTML.
2) A huge community resource which has a ton of information before you.
3) Connectivity ability lets you to connect to different interfaces and predefined libraries.
4) Execution is very fast because it uses less system resources, etc.

16. How can we destroy the cookie?
- clear all the cookie variables, by using unset() function i.e. unset($_COOKIE).
- destroy the cookie value by it name, if the cookie variable name is 'usename' i.e. $_COOKIE['username'].

17. What is the difference between ereg_replace() and eregi_replace()?
- ereg_replace() -- Replace regular expression
- eregi_replace() -- Replace regular expression case insensitive

nl2br() in php

What is meant by nl2br()?
- nl2br -- Inserts HTML line breaks before all newlines in a string
- Example :
echo nl2br("foo isn't\n bar");
/*output :
foo isn't

bar
*/
?>

strstr() and stristr() in php

What is the functionality of the function strstr and stristr?
- strstr -- Find first occurrence of a string
- Example :
$email = 'user@example.com';
$domain = strstr($email, '@');
echo $domain; // prints @example.com
?>
- stristr -- Case-insensitive strstr()
- Example :
$email = 'USER@EXAMPLE.com';
$domain = stristr($email, 'e');
echo $domain;
// outputs ER@EXAMPLE.com
?>

What is meant by nl2br()?
- nl2br -- Inserts HTML line breaks before all newlines in a string
- Example :
echo nl2br("foo isn't\n bar");
/*output :
foo isn't

bar
*/
?>

get image size in php

How can we get the properties (size, type, width, height) of an image using PHP
image functions?
- getimagesize -- Get the size of an image
- Returns an array with 4 elements.
- Index 0 contains the width of the image in pixels.
- Index 1 contains the height.
- Index 2 is a flag indicating the type of the image: 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF(intel byte order), 8 = TIFF(motorola byte order), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM. These values correspond to the IMAGETYPE constants that were added in PHP 4.3.
- Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.
- Example:

list($width, $height, $type, $attr) = getimagesize("reset.jpg");
echo "

Width : ".$width;
echo "
Height : ".$height;
echo "
Type : ".$type;
echo "
Attribute : ".$attr;

/* Output :

Width : 53
Height : 22
Type : 2
Attribute : width="53" height="22"

*/
?>

Monday, September 1, 2008

Iterative statements (loops concepts) in php

Explain about PHP looping?
Looping statements are used in PHP to execute the code for a developer defined number of times.
PHP has these following looping statements they are
- while() loop,
- do while() loop,
- for() loop and
- foreach() loop

/* Example for while() loop */
echo "Example using while() loop to display 1-4 numbers
";
$i=1;
while($i<5){
echo $i." ";
$i++;
}

echo "
Example using do-while() loop to display 1-4 numbers
";
/* Example for do-while() loop */
$i=1;
do {
echo $i." ";
$i++;
}while($i<5);

echo "
Example using for() loop to display 1-4 numbers
";
/* Example for for() loop */
for($i=1;$i<5;$i++){
echo $i." ";
}

echo "
Example using foreach() loop to display 1-4 numbers
";
/* Example for for() loop */
$a = array(1,2,3,4);
foreach($a as $i){
echo $i." ";
}
?>

Difference between sizeof() and count() in php

- count() -- Count elements in a variable
- syntax for count() [int count ( mixed var [, int mode])]
- If the optional mode parameter is set to COUNT_RECURSIVE (or 1), count() will recursively count the array. This is particularly useful for counting all the elements of a multidimensional array. The default value for mode is 0.

- sizeof() function is an alias of count() function
- Example below:
/* Simple Example */
$a = array(1,2,3,4);
echo "
Example #1";
echo "
Count of A array is :".count($a);
echo "
Size of A array is :".sizeof($a);

echo "

Example #2";
$food = array('fruits' => array('orange', 'banana', 'apple'),
'veggie' => array('carrot', 'collard', 'pea'));

/* recursive count */
/* count($food, COUNT_RECURSIVE) equals to count($food, 1) */
echo "
Count of A array is :".count($food, COUNT_RECURSIVE);

echo "
Size of A array is :".sizeof($food, 1);

/* normal count */
/* count($food, COUNT_RECURSIVE) equals to count($food, 1) */
echo "

Example #3";
echo "
Count of A array is :".count($food, 0);
echo "
Size of A array is :".sizeof($food);

echo "

Conclusion :
The sizeof() function is an alias for count().
";
?>

Saturday, August 30, 2008

Interview Questions in PHP and General informations

1. How old PHP language is?
- PHP began in 1994, so 14 years old.

2. What are different names of PHP?
- PHP originally stood for Personal Home Page.
- At the formation of PHP 3, name changed into Hypertext Preprocessor by Zeev Suraski and Andi Gutmans, two Israeli developers

3. What is latest name of PHP?
- Hypertext Preprocessor

4. Which databases you can use with PHP?
- * Abstraction Layers
o DBA — Database (dbm-style) Abstraction Layer
o dbx
o ODBC — ODBC (Unified)
o PDO — PHP Data Objects

* Vendor Specific Database Extensions
o dBase
o DB++
o FrontBase
o filePro
o Firebird/InterBase
o Informix
o IBM DB2 — IBM DB2, Cloudscape and Apache Derby
o Ingres II
o MaxDB
o mSQL
o Mssql — Microsoft SQL Server
o MySQL
o Mysqli — MySQL Improved Extension
o OCI8 — Oracle OCI8
o Ovrimos SQL
o Paradox — Paradox File Access
o PostgreSQL
o SQLite
o SQLite3
o Sybase

5. Why PHP is called a scripting language?
A scripting language, script language or extension language, is a programming language that controls a software application. "Scripts" are often treated as distinct from "programs", which execute independently from any other application. At the same time they are distinct from the core code of the application, which is usually written in a different language, and by being accessible to the end user they enable the behavior of the application to be adapted to the user's needs. Scripts are often, but not always, interpreted from the source code or "semi-compiled" to bytecode which is interpreted, unlike the applications they are associated with, which are traditionally compiled to native machine code for the system on which they run. Scripting languages are nearly always embedded in the application with which they are associated.

6. Is PHP object oriented language?
- Yes, PHP 5 and above is an OOPs

7. What is different between PHP & ASP.NET?
- PHP is Open Source Software
- ASP.NET is Payment Software

- PHP is closely with MySQL Database because both are FREE softwares, MySQL is an Open Source SQL database
- ASP.NET is closely with MSSQL (Microsoft Sql Server) but it also payment

- PHP is very easy to learn and implement, style like C language
- ASP.NET using like ASP, also we need basic knowledge about .NET framework

- PHP having no Web services, to access the 3rd party controls
- ASP.NET we can use Web Services easily

- PHP uses both IIS server and Apache Server
- ASP.NET uses IIS Server

- ASP.NET being object oriented is more "organized" and maintainable than scripted PHP. Besides being fully compiled, ASP.NET platform offers loads of pure OO features like inheritance, polymorphism, overloading etc. Newer versions of PHP support OOP but its very limited compared to ASP.NET.

- Example program : #1
< %
' ASP Example
myFormVal = request.form("myInputField")
myQSval = request.querystring("myQSitem")
myVal = request.item("myFormOrQSitem")
%>

// PHP 4.1+ Example
$myFormVal = $_POST['myInputField'];
$myQSval = $_REQUEST['myQSitem'];

// PHP 3+ Example
$myFormVal = $HTTP_POST_VARS['myInputField'];

// If register_globals = on
$myVal = $myFormOrQSitem;
?>

- Example program : #2

< %
' VBScript Example
Option Explicit
myVar = 1
myOtherVar = myVar
myVar = 2

' myResult will be 3
myResult = myVar + myOtherVar
%>
// PHP Example
$myVar = 1;
'Use the ampersand to make a reference
$myOtherVar = &$myVar;
$myVar = 2;

// $myResult will be 4
$myResult = $myVar + $myOtherVar;
?>


8. What is the difference between include & require?
- The require() function is identical to include(), except that it handles errors differently.

- The include() function generates a warning (but the script will continue execution) while the require() function generates a fatal error (and the script execution will stop after the error).

- Example for include() function
/* Example for include */
include("wrongFile.php");
echo "Hello World!";

/* If the file 'wrongFile.php' is not available then Warning error and below will happen */
?>
Warning: include(wrongFile.php) [function.include]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5

Warning: include() [function.include]:
Failed opening 'wrongFile.php' for inclusion
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5

Hello World!

- Example for require() function
/* Example for require */
include("wrongFile.php");
echo "Hello World!";

/* If the file 'wrongFile.php' is not available then Fatal error and below will happen */
?>

Warning: require(wrongFile.php) [function.require]:
failed to open stream:
No such file or directory in C:\home\website\test.php on line 5

Fatal error: require() [function.require]:
Failed opening required 'wrongFile.php'
(include_path='.;C:\php5\pear')
in C:\home\website\test.php on line 5


9. What is the difference between include_once & require_once?

- both are similar like above but with one major difference
- both the functions checks the given file is already loaded or not, if the file is already loaded then the given file is not
loaded again or else it will load the file.

10. What is error control operator?

- Reporting Errors
To report errors from an internal function, you should call the php3_error() function. This takes at least two parameters -- the first is the level of the error, the second is the format string for the error message (as in a standard printf() call), and any following arguments are the parameters for the format string. The error levels are:

- E_NOTICE
Notices are not printed by default, and indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. For example, trying to access the value of a variable which has not been set, or calling stat() on a file that doesn't exist.

- E_WARNING
Warnings are printed by default, but do not interrupt script execution. These indicate a problem that should have been trapped by the script before the call was made. For example, calling ereg() with an invalid regular expression.

- E_ERROR
Errors are also printed by default, and execution of the script is halted after the function returns. These indicate errors that can not be recovered from, such as a memory allocation problem.

- E_PARSE
Parse errors should only be generated by the parser. The code is listed here only for the sake of completeness.

- E_CORE_ERROR
This is like an E_ERROR, except it is generated by the core of PHP. Functions should not generate this type of error.

- E_CORE_WARNING
This is like an E_WARNING, except it is generated by the core of PHP. Functions should not generate this type of error.

- E_COMPILE_ERROR
This is like an E_ERROR, except it is generated by the Zend Scripting Engine. Functions should not generate this type of error.

- E_COMPILE_WARNING
This is like an E_WARNING, except it is generated by the Zend Scripting Engine. Functions should not generate this type of error.

- E_USER_ERROR
This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). Functions should not generate this type of error.

- E_USER_WARNING
This is like an E_WARNING, except it is generated by using the PHP function trigger_error(). Functions should not generate this type of error.

- E_USER_NOTICE
This is like an E_NOTICE, except it is generated by using the PHP function trigger_error(). Functions should not generate this type of error.

- E_ALL
All of the above. Using this error_reporting level will show all error types.


11. What will these functions do? (explode(), file(), mysql_insert_id(), time() )
- Example for explode()
- explode() -- Split a string by string

/* Example for explode() */
$pizza = "piece1-piece2-piece3-piece4-piece5-piece6";
$pieces = explode("-", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
echo $pieces[4]; // piece5
?>

- Example for file()
- file() -- Reads entire file into an array
// Get a file into an array. In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.example.com/');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
echo "Line #{$line_num} : " . htmlspecialchars($line) . "
\n";
}
?>

- Example for mysql_insert_id()
- mysql_insert_id() -- Get the ID generated from the previous INSERT operation
- $link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
?>

12. Which function gives us absolute path of a file on the server?
- getcwd() -- gets the current working directory
-
/* current directory *
echo getcwd() . "\n"; /* /home/didou */

?>

13. Can we do automatic FTP using PHP? How?
- Yes, lots of FTP function available in PHP
- Ex: ftp_login(), ftp_mkdir (), ftp_ssl_connect() etc.,
-
// set up basic ssl connection
$conn_id = ftp_ssl_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

echo ftp_pwd($conn_id); // /

// close the ssl connection
ftp_close($conn_id);
?>

14. Can we do Flash programming using PHP? How?
- Yes, lots of Flash programming functions available in PHP
- Ex: swf_actiongeturl(), swf_endbutton() etc.,

15. Can we create dynamic PDF document using PHP? How?
- Yes, lots of functions available in PHP
- The PDF functions in PHP can create PDF files using the PDFlib library created by Thomas Merz.
- Example :

$pdf = pdf_new();
pdf_open_file($pdf, "test.pdf");
pdf_set_info($pdf, "Author", "Uwe Steinmann");
pdf_set_info($pdf, "Title", "Test for PHP wrapper of PDFlib 2.0");
pdf_set_info($pdf, "Creator", "See Author");
pdf_set_info($pdf, "Subject", "Testing");
pdf_begin_page($pdf, 595, 842);
pdf_add_outline($pdf, "Page 1");
$font = pdf_findfont($pdf, "Times New Roman", "winansi", 1);
pdf_setfont($pdf, $font, 10);
pdf_set_value($pdf, "textrendering", 1);
pdf_show_xy($pdf, "Times Roman outlined", 50, 750);
pdf_moveto($pdf, 50, 740);
pdf_lineto($pdf, 330, 740);
pdf_stroke($pdf);
pdf_end_page($pdf);
pdf_close($pdf);
pdf_delete($pdf);
echo "Finished";
?>

16. In which language PHP code is written?
- PHP's Common Gateway Interface binaries written in the C programming language

Wednesday, August 13, 2008

PHP Interview Questions in Photon Infotech

hai all,

Anybody know the PHP interview questions asked in Photon Infotech?

Sample question :

1. What is the uses and syntax of UCFIRST() function?
- ucfirst -- Make a string's first character uppercase
- Example :
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!

$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

2. How to get the current working browser using php code?
(i) Method 1: $_SERVER['HTTP_USER_AGENT']
Example :
if (substr_count(strtolower($_SERVER['HTTP_USER_AGENT']),"firefox"))/* Firefox browser*/
echo "My name's Firefox";
else if (substr_count(strtolower($_SERVER['HTTP_USER_AGENT']),"opera")) /* Opera browser */
echo "My name's Opera";
else if (substr_count(strtolower($_SERVER['HTTP_USER_AGENT']),"msie")) /* IE browser */
echo "My name's IE ";
else if (substr_count(strtolower($_SERVER['HTTP_USER_AGENT']),"safari")) /* Safari browser */
echo "My name's Safari";
else
echo "I don't know my name ";
?>

(ii) Method 2
- get_browser() built-in function in php
- get_browser -- Tells what the user's browser is capable of
- Example :
echo $_SERVER['HTTP_USER_AGENT'] . "\n";

$browser = get_browser();

foreach ($browser as $name => $value) {
echo "$name $value
\n";
}

?>

3. Worked projects related questions
4. Most of the question asked in php.ini setting
Example :
1. What is the maximum file size to upload by default?
- 2MB
2. What is the minimum session expiry time by default?
- session.cache_expire is 180 seconds

3. Necessity of md5 and its purpose?
4. Difference b/w PHP 4 and PHP 5?
5. PHP INI?
6. Different types of Payment gate way?
7. Different types of PHP Frame Works?

Popular Posts