PHP Interview Questions With Answers
1)What is PHP?
PHP: Hypertext Preprocessor is open source server-side scripting language that is widely used for web development. PHP scripts are executed on the server. PHP allows writing dynamically generated web pages efficiently and quickly. The syntax is mostly borrowed from C, Java and perl. PHP is free to download and use.
2)What is PEAR in php?
PEAR(PHP Extension and Application Repository) is a framework and repository for reusable PHP components. PEAR is a code repository containing all kinds of php code snippets and libraries.
PEAR also offers a command-line interface that can be used to automatically install "packages".
3)Explain how to submit form without a submit button.
We can achieve the above task by using JavaScript code linked to an event trigger of any form field and call the document.form.submit() function in JavaScript code.
4)Echo vs. print statement.
echo() and print() are language constructs in PHP, both are used to output strings. The speed of both statements is almost the same
echo() can take multiple expressions whereas print cannot take multiple expressions.
Print return true or false based on success or failure whereas echo doesn't return true or false.
5)$message vs. $$message in PHP.
$message is a variable with a fixed name. $$message is a variable whose name is stored in $message.
If $message contains "var", $$message is the same as $var.
6)Explain the different types of errors in PHP.
Notices, Warnings and Fatal errors are the types of errors in PHP
Notices:
Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.
Warnings:
Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.
Fatal errors:
Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.
7)Explain the importance of the function htmlentities.
The htmlentities() function converts characters to HTML entities.
8)What is MIME?
MIME - Multi-purpose Internet Mail Extensions.
MIME types represents a standard way of classifying file types over Internet.
Web servers and browsers have a list of MIME types, which facilitates files transfer of the same type in the same way, irrespective of operating system they are working in.
A MIME type has two parts: a type and a subtype. They are separated by a slash (/).
MIME type for Microsoft Word files is application and the subtype is msword, i.e. application/msword.
9)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:
<?header('Location: http://www.php.net')?>
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.
10)Why PHP is also called as Scripting language?
PHP is basically a general purpose language, which is used to write scripts. Scripts are normal computer files that consist of instructions written in PHP language. It tells the computer to execute the file and print the output on the screen. PHP is used for webpages and to create websites, thus included as scripting language.
ADS HERE !!!