Basic PHP Interview Questions Part 2

1. How To Read the Entire File into a Single String?

$file = file_get_contents("/windows/system32/drivers/etc/services");
print("Size of the file: ".strlen($file)."n");

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

The header() function is used for redirect the page.if you want to redirect one page to another we can use it.

3. What is the difference between the functions unlink and unset?

unlink() is a function for file system handling. It will simply delete the file in context.
unset() is a function for variable management. It will make a variable undefined.

4. How can we submit a form without a submit button?

If you don't want to use the Submit button to submit a form, you can use normal hyper links to submit a form. But you need to use some JavaScript code in the URL of the link.
<a href="javascript: document.myform.submit();">Click Me</a>

5. Are objects passed by value or by reference?

Everything is passed by value.

6. What is the difference between ereg_replace() and eregi_replace()?

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

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

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

8. What is meant by 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.
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.

9.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. For example, "Hello!" will be stored as "Hello! " in CHAR(10) 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. For example, "Hello!" will be stored as "Hello!" in VARCHAR(10) column.

10. What is the maximum size of a file that can be uploaded using PHP and how can we change this?

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