About Me

kolkata, west bengal, India
Working on Vovici Survey Tool in PWC kolkata.

Wednesday, July 14, 2010

Php interview questions

1)What’s the difference between include and require? - It’s how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

2)Explain the ternary conditional operator in PHP? - Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.

3)For printing out strings, there are echo, print and printf. Explain the differences. - echo is the most primitive of them, and just outputs the contents following the construct to the screen. print is also a construct (so parentheses are optional when calling it), but it returns TRUE on successful output and FALSE if it was unable to print out the string. However, you can pass multiple parameters to echo, like:



and it will output the string "Welcome to TechInterviews!" print does not take multiple parameters. It is also generally argued that echo is faster, but usually the speed advantage is negligible, and might not be there for future versions of PHP. printf is a function, not a construct, and allows such advantages as formatted output, but it’s the slowest way to print out data out of echo, print and printf.

4)What’s the difference between htmlentities() and htmlspecialchars()? - htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.

5)What is the use of ob_start() in PHP?
Actually, ob_start() tells PHP to start output buffering, meaning that anything you output after ob_start() wont be sent to the browser until the end of the page or ob_end() etc are reached.

So that means that once you use ob_start() and echo something out, you can still set cookies without any errors. For example:


ob_start();
echo "this will work";
setcookie("test", true);

ob_end_flush();

?>

6)what is the difference between ph4 and php5
In PHP4, everything was passed by value, including objects. This has changed in PHP5 -- all objects are now passed by reference.
PHP5 introduces a new unified constructor/destructor names. In PHP4, a constructor was simply a method that had the same name as the class itself. This caused some headaches since if you changed the name of the class, you would have to go through and change every occurrence of that name.

In PHP5, all constructors are named __construct(). That is, the word construct prefixed by two underscores. Other then this name change, a constructor works the same way.Also, the newly added __destruct() (destruct prefixed by two underscores) allows you to write code that will be executed when the object is destroyed.

Type Hinting

PHP5 introduces limited type hinting. This means you can enforce what kind of variables are passed to functions or class methods. The drawback is that (at this time), it will only work for classes or arrays -- so no other scalar types like integers or strings.
PHP finally introduces exceptions! An exception is basically an error. By using an exception however, you gain more control the simple trigger_error notices we were stuck with before.
Standard PHP Library
use this link to know more
http://prakashadmane.blogspot.com/2008_01_01_archive.html

7)What are the differences between Get and post methods

1. By using Post method we can send unlimited data,But it's
not possible in the case of Get. Get support maximum 200
characters or 2 MB data.
2. Get method is not secure as anyone can see it's content
in the URL.It doesn't happen in case of Post method.

8)How can we submit a form without a submit button?

using javascript
document.form.submit();
9)How many ways we can retrieve the date in result set of mysql using php?

4 ways

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

mysql_fetch_object : will return the results from database
as objects. fields will be accessible like in objects
i.e $result->name,$result->cust_name

mysql_fetch_array : will return the results from database as
array. fields will be accessible like in objects
i.e $result[name],$result[cust_name]

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


$Message = "php";
$you= "java";

echo $message //Output:- php
echo $$message //output :-java

It means
$message is a variable and
$$Message is variable of variable

A variable of variable allows us to change the name of
variable dinamically

1 comment:

  1. Arrays
    How can I check if a value is already in an array?
    How can I create an array of numbers easily?
    How can I create an array of the letters of the alphabet?
    How can I display a 2 dimensonal array?
    How can I display values in a two dimensional array?
    How can I easily view all members of an array?
    How can I loop through the members of an array?
    How can I mix up the order of values in an array?
    How can I reset an array in PHP?
    How can I reverse sort an array keeping the correlation between the index and value?
    How can I sort a multi-dimensional array?
    How can I sort an array keeping the correlation between the index and value?
    How do I add to the beginning of an array and find the number of elements in it?
    How do I add to the end of an array and know how large the array is?
    How do I check if a variable is of array type?
    How do I count the number of times a value appears in an array?
    How do I find if a value is already in an array or not?
    How do I find out if a value is already in an array?
    How do I find the size of an array?
    How do I pick a random value from an array?
    How do I remove an element from an array without changing the index values for the rest of the array?
    How do I remove and view the last element of an array?
    How do I remove the first element from an array?
    How do I return all the values in an array?
    How do I reverse sort an array by key?
    How do I reverse sort the members of an array?
    How do I reverse the order of the elements in an array?
    How do I sort alphanumeric array data correctly?
    How do I sort an array by key?
    How do I sort the members of an array by value?
    How do I turn an array into a string?
    How do I write my own sort function?
    How do we sort an array of names taken from a text file, displaying only unique names?
    How do you remove duplicate values from an array?
    How to point internal pointer to first element of an array?
    I am not interested in the values in the arrays, how can I discard them?
    I have an array of numbers and many repeat, how to list all items in order of maximum occurence?
    I want to invert my array, can I do this?
    Errors
    I get a parse error - unexpected ; at line x message. What is this?
    I get a PHP error - maximum execution time exceeded. What is this?
    I get a PHP notice for string to array conversion - help?
    I get a PHP warning for array to string conversion - what is this?
    I get the error message headers already sent, what does this mean?
    Parse error in PHP - unexpected T_variable at line x. What is this error?
    PHP error - use of undefined constant at line x... what does this mean?
    Files
    How can I export data into Word/Excel documents?
    How can i upload large files like mp3 songs using php?
    How can I view a Word document in a PHP page?
    How do I open a file to write content to?
    I am trying to find the most recent directory that I am working in. example http://www.mysite.com/apples/index.php how do I get php to find the directory "apples" so I can make it a directory
    What does file_get_contents do?
    What is the use of file in php?
    Where is a text file i created kept?
    Forms
    Can I use a variable from a .php file to give a value to an HTML FormMail form field thus: ? Thank you
    How can I access information sent through GET on a form?
    How can I access information sent through POST on a form?
    How can I check a value entered in a field on my form is a number?
    How can I check that a data value is alphanumeric?
    How do I check for an empty field in a form?
    How do I check that a valid email address is entered?
    How do I email the contents of a form to me?
    How do I escape data that is going into a database?
    How do I know if magic quotes is switched on?
    How do I make a website field mandatory?
    How do I remove escape characters from data?
    How do I remove HTML tags from a string?
    What are magic quotes?

    ReplyDelete