PHP freshers Interview Questions/PHP Interview Questions and Answers for Freshers & Experienced

What is the use of strip_tags() method?

strip_tags() function is used to retrieve the string from a text by omitting HTML, XML and PHP tags. This function has one mandatory parameter and one optional parameter. The optional parameter is used to accept particular tags.

Sample code:

//Remove all tags from the text
echo strip_tags("<b>PHP</b> is a popular <em>scripting</em> language");
//Remove all tags excluding <b> tag
echo strip_tags("<b>PHP</b> is a popular <em>scripting</em> language","<b>");

Posted Date:- 2021-08-17 11:01:34

What is the function mysql_pconnect() useful for?

mysql_pconnect() ensure a persistent connection to the database, it means that the connection does not close when the PHP script ends.

This function is not supported in PHP 7.0 and above

Posted Date:- 2021-08-17 10:59:31

Explain type hinting in PHP

In PHP, type hinting is used to specify the expected data type (arrays, objects, interface, etc.) for an argument in a function declaration. It was introduced in PHP 5.
Whenever the function is called, PHP checks if the arguments are of a user-preferred type or not. If the argument is not of the specified type, the run time will display an error and the program will not execute.
It is helpful in better code organization and improved error messages.

Posted Date:- 2021-08-17 10:56:33

How to destroy a cookie in PHP?

There is not a way to directly delete a cookie. Just use the setcookie function with the expiration date in the past, to trigger the removal mechanism in your web browser.

Posted Date:- 2021-08-17 10:53:12

What is the use of “echo” in PHP?

In PHP, echo is used to print data on the webpage.
Example: <?php echo ‘Car insurance’; ?>

Posted Date:- 2021-08-17 10:52:30

Which function is used in PHP to delete a file?

unlink() function is used in PHP to delete any file.

Sample code:

Posted Date:- 2021-08-17 10:50:21

What is the meaning of a final method and a final class?

The final keyword in a declaration of the method indicates that the method cannot be overridden by subclasses. A class that is declared as final cannot be subclassed.
This is especially useful when we are creating an immutable class like the String class. Only classes and methods may be declared final, properties cannot be declared as final.

Posted Date:- 2021-08-17 10:47:51

How is it possible to set an infinite execution time for PHP script?

The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error 'maximum execution time exceeded.' It is also possible to specify this in the php.ini file.

Posted Date:- 2021-08-17 10:46:20

How failures in execution are handled with include() and require() functions?

If the function require() cannot access the file then it ends with a fatal error. However, the include() function gives a warning, and the PHP script continues to execute.

Posted Date:- 2021-08-17 10:45:43

What is the use of the function 'imagetypes()'?

imagetypes() gives the image format and types supported by the current version of GD-PHP.

Posted Date:- 2021-08-17 10:44:57

How can we create a database using PHP and MySQL?

The basic steps to create MySQL database using PHP are:

1. Establish a connection to MySQL server from your PHP script.
2. If the connection is successful, write a SQL query to create a database and store it in a string variable.
3. Execute the query.

Posted Date:- 2021-08-17 10:43:42

How many types of array are there in PHP?

There are three types of array in PHP:

1. Indexed array: an array with a numeric key.
2. Associative array: an array where each key has its specific value.
3. Multidimensional array: an array containing one or more arrays within itself.

Posted Date:- 2021-08-17 10:39:53

Explain which is required to be able to utilize image function?

The GD library is required to be able to do image functions. It also helps to execute more image functions.

Posted Date:- 2021-08-17 10:37:55

What is cookie and why do we use it?

A cookie is a small piece of information stored in a client browser. It is a technique utilized to identify a user using the information stored in their browser. Utilizing PHP, we can both set and get COOKIE.

Posted Date:- 2021-08-17 10:37:29

What is session and why do we use it?

A session is a super global variable that preserves data across subsequent pages. Session uniquely defines all users with a session ID. So it supports building a customized web application where user tracking is required.

Posted Date:- 2021-08-17 10:37:00

What is PDO in PHP?

PDO stands for PHP Data Object. PDO is a set of PHP extensions that provide a core PDO class and database, specific drivers. The PDO extension can access any database which is written for the PDO driver. There are several PDO drivers available which are used for FreeTDS, Microsoft SQL Server, IBM DB2, Sybase, Oracle Call Interface, Firebird/Interbase 6 and PostgreSQL databases, etc.

It gives a lightweight, vendor-neutral, data-access abstraction layer. Hence, no matter what database we use, the function to issue queries and fetch data will be the same. And, it focuses on data access abstraction instead of database abstraction.

Posted Date:- 2021-08-17 10:35:58

How is it possible to set an infinite execution time for PHP script?

The set_time_limit(0) added at the beginning of a script sets to infinite the time of execution to not have the PHP error ‘maximum execution time exceeded.’ It is also possible to specify this in the php.ini file.

Posted Date:- 2021-08-17 10:30:38

How can you increase the maximum execution time of a script in PHP?

You need to change the value of the max_execution_time directive in the php.ini file for increasing the maximum execution time.
For Example,
if you want to set the max execution time for 130 seconds, then set the value as follows,

max_execution_time = 130

Posted Date:- 2021-08-17 10:29:30

Which function is used in PHP to check the data type of any variable?

gettype() function is used to check the data type of any variable.

Sample cecho gettype(true).''; //boolean
echo gettype(10).''; //integer
echo gettype('Web Programming').''; //string
echo gettype(null).''; //NULLode:

Posted Date:- 2021-08-17 10:27:51

How is the comparison of objects done in PHP?

We use the operator '==' to test is two objects are instanced from the same class and have same attributes and equal values. We can test if two objects are referring to the same instance of the same class by the use of the identity operator '==='.

Posted Date:- 2021-08-17 10:25:49

Is multiple inheritance supported in PHP?

PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword 'extended'.

Posted Date:- 2021-08-17 10:25:12

How can you execute PHP script from the command line?

Answer: You have to use PHP command in the command line to execute a PHP script. If the PHP file name is test.php then the following command is used to run the script from the command line.
php test.php

Posted Date:- 2021-08-17 10:24:27

Is PHP a strongly typed language?

No. PHP is a weakly typed or loosely typed language.

This means PHP does not require to declare data types of the variable when you declare any variable like the other standard programming languages C# or Java. When you store any string value in a variable, then the data type is the string and if you store a numeric value in that same variable then the data type is an Integer.
Sample code:
$var = "Hello"; //String
$var = 10; //Integer

Posted Date:- 2021-08-17 10:22:22

Why do we use PHP?

There are several benefits of using PHP. First of all, it is totally free to use. So anyone can use PHP without any cost and host the site at a minimal cost.

It supports multiple databases. The most commonly used database is MySQL which is also free to use. Many PHP frameworks are used now for web development, such as CodeIgniter, CakePHP, Laravel, etc.

Posted Date:- 2021-08-17 10:20:25

How to send a mail in PHP?

You can send an e-mail in PHP with mail() function or SMTP details.

Posted Date:- 2021-08-17 10:18:45

What is the use of count function in MySQL?

count() function is used for fetching the total number records in a table.

Posted Date:- 2021-08-17 10:17:20

What are tags used?

They allow making the result of the expression between the tags directly to the browser response.

Posted Date:- 2021-08-17 10:16:42

Explain the main types of errors.

The 3 main types of errors in PHP are:

1. Notices: Notices are non-critical errors that can occur during the execution of the script. These are not visible to users. Example: Accessing an undefined variable.
2. Warnings: These are more critical than notices. Warnings don’t interrupt the script execution. By default, these are visible to the user. Example: include() a file that doesn’t exist.
3. Fatal: This is the most critical error type which, when occurs, immediately terminates the execution of the script. Example: Accessing a property of a non-existent object or require() a non-existent file.

Posted Date:- 2021-08-17 10:15:57

What is the use of header() function in PHP?

The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output. For example, you can't print any HTML element before using this function.

Posted Date:- 2021-08-17 10:13:11

What is the use of session_start() and session_destroy() functions in PHP?

The session_start() function is used to start a new session. Also, it can resume an existing session if it is stopped. In this particular case, the return will be the current session if resumed.


The session_destroy() function is used to destroy all of the session variables as given below:

Posted Date:- 2021-08-17 10:11:19

What are the different types of Array in PHP?

There are 3 types of Arrays in PHP:
1. Indexed Array – An array with a numeric index is known as the indexed array. Values are stored and accessed in linear fashion.
2, Associative Array – An array with strings as index is known as the associative array. This stores element values in association with key values rather than in a strict linear index order.
3. Multidimensional Array – An array containing one or more arrays is known as multidimensional array. The values are accessed using multiple indices.

Posted Date:- 2021-08-17 10:09:05

What is the most used method for hashing passwords in PHP?

The crypt() function is used for this functionality as it provides a large number of hashing algorithms that can be used. These algorithms include sha1, sha256, or md5 which are designed to be very fast and efficient.

Posted Date:- 2021-08-17 10:05:52

What is "print" in PHP?

PHP print output a string. It is a language construct not a function. So the use of parentheses is not required with the argument list. Unlike echo, it always returns 1.

Posted Date:- 2021-08-17 10:05:03

What is NULL?

NULL is a particular type which contains only one value: NULL. If you need any variable to set NULL, just assign it.

Posted Date:- 2021-08-17 10:04:19

What are traits?

Traits are a mechanism that lets you create reusable code in PHP and similar languages where multiple inheritances are not supported. It’s not possible to instantiate it on its own.
A trait is intended to reduce the limitations of single inheritance by enabling a developer to reuse sets of methods freely in many independent classes living in different hierarchies of class.

Posted Date:- 2021-08-17 10:03:26

Tell me some of the disadvantages of PHP

The cons of PHP are:
1. PHP is not suitable for giant content-based web applications.
2. Since it is open-source, it is not secure. Because ASCII text files are easily available.
3. Change or modification in the core behavior of online applications is not allowed by PHP.
4, If we use more features of the PHP framework and tools, it will cause poor performance of online applications.
5. PHP features a poor quality of handling errors. PHP lacks debugging tools, which are needed to look for warnings and errors. It has only a few debugging tools in comparison to other programming languages.

Posted Date:- 2021-08-17 10:00:17

What is the meaning of a final class and a final method?

The final keyword in a method declaration indicates that the method cannot be overridden by subclasses. A class that is declared final cannot be subclassed. This is particularly useful when we are creating an immutable class like the String class.Properties cannot be declared final, only classes and methods may be declared as final.

Posted Date:- 2021-08-17 09:54:37

Describe which programming language does PHP parallel to?

The PHP syntax relates Perl and C.

Posted Date:- 2021-08-17 09:49:28

Explain the importance of Parser in PHP?

A PHP parser is software that converts source code into the code that computer can understand. This means whatever set of instructions we give in the form of PHP code is converted into a machine-readable format by the parser.

Posted Date:- 2021-08-17 09:42:42

How can PHP and HTML interact?

PHP scripts have the ability to generate HTML, and it is possible to pass information from HTML to PHP.

PHP is a server-side language whereas HTML is a client-side language. So PHP executes on the server-side and gets its results as strings, objects, arrays, and then we use them to display its values in HTML.

This interaction helps bridge the gaps and use the best of both languages.

Posted Date:- 2021-08-17 09:41:00

What are the rules for naming a PHP variable?

The following two rules are needed to be followed while naming a PHP variable:
1. It evaluates to FALSE in a Boolean context.
2. It returns FALSE when tested with IsSet() function.

Posted Date:- 2021-08-17 09:39:18

How do you display the output directly to the browser?

To display the output directly to the browser, I will use the special tags <?= and ?>.

Posted Date:- 2021-08-17 09:33:44

Explain the difference between static and dynamic websites?

In static websites, content can't be changed after running the script. You can't change anything on the site. It is predefined.

In dynamic websites, content of script can be changed at the run time. Its content is regenerated every time a user visit or reload. Google, yahoo and every search engine is the example of dynamic website.

Posted Date:- 2021-08-17 09:32:33

What does PEAR stands for?

PEAR stands for “PHP Extension and Application Repository”. PEAR is a framework and repository for all of the reusable PHP components.

PEAR provides a higher level of programming for web developers. It contains all kinds of PHP code snippets and libraries. It also provides you with a command-line interface to automatically install packages.

Posted Date:- 2021-08-17 09:31:09

Is PHP a case sensitive language?

PHP is partially case sensitive. The variable names are case-sensitive but function names are not. If you define the function name in lowercase and call them in uppercase, it will still work. User-defined functions are not case sensitive but the rest of the language is case-sensitive.

Posted Date:- 2021-08-17 09:30:10

How to execute a PHP script from the command line?

To execute a PHP script, use the PHP Command Line Interface (CLI) and specify the file name of the script in the following way:

1.php script.php

Posted Date:- 2021-08-17 09:29:13

How to select a database?

The PHP Data Objects (PDO) is a lightweight, and consistent interface used to access databases in PHP.

Posted Date:- 2021-08-17 09:28:25

What types of loops exist in PHP?

for, while, do while and foreach.

Posted Date:- 2021-08-17 09:27:37

What is PEAR in PHP?

PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries. It also provides a command line interface to install “packages” automatically.

Posted Date:- 2021-08-17 09:26:57

What is PHP?

PHP is a widely-used, open-source server-side scripting language. PHP is an acronym for “PHP: Hypertext Preprocessor.” It allows the developers to develop dynamic web applications. PHP has various frameworks and CMS for developing dynamic and interactive websites.

Posted Date:- 2021-08-17 09:25:33

R4R Team
R4R provides PHP Freshers questions and answers (PHP Interview Questions and Answers) .The questions on website is done by expert team! Mock Tests and Practice Papers for prepare yourself.. Mock Tests, Practice Papers,PHP freshers Interview Questions,PHP Freshers & Experienced Interview Questions and Answers,PHP Objetive choice questions and answers,PHP Multiple choice questions and answers,PHP objective, PHP questions , PHP answers,PHP MCQs questions and answers R4r provides Python,General knowledge(GK),Computer,PHP,SQL,Java,JSP,Android,CSS,Hibernate,Servlets,Spring etc Interview tips for Freshers and Experienced for PHP fresher interview questions ,PHP Experienced interview questions,PHP fresher interview questions and answers ,PHP Experienced interview questions and answers,tricky PHP queries for interview pdf,complex PHP for practice with answers,PHP for practice with answers You can search job and get offer latters by studing .learn in easy ways .