PHP Interview Questions

There is given PHP interview questions and answers that have been asked in many companies. Let's see the list of top PHP interview questions.

What are the encryption functions available in PHP ?

crypt(), Mcrypt(), hash() are used for encryption in PHP.

What is a composer in PHP?

It is an application-level package manager for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you..

Explain the difference between __sleep and __wakeup method in PHP?

The __sleep method returns the array of all the variables that should be saved, while __wakeup method retrieves them..

What is rand() function in PHP?

The rand() function is used to generate random numbers..

What is SQL injection?

SQL injection is a malicious code injection technique that might destroy your database. It exploiting SQL vulnerabilities in Web applications. It is one of the most common web hacking techniques..

Describe how PHP and Javascript can interact?

The PHP and Javascript could not directly interact because PHP is a server-side scripting language and Javascript is a client-side scripting language. But, we can change variables, because PHP can generate JavaScript code to be performed by the web browser and it is likely to pass particular variables behind to PHP into the URL.

.

What are tags used?

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

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..

Which functions are used to remove whitespaces from the string?

There are three functions in PHP to remove the whitespaces from the string.

  • trim() – It removes whitespaces from the left and right side of the string.
  • ltrim() – It removes whitespaces from the left side of the string.
  • rtrim() – It removes whitespaces from the right side of the string.
$str = " Tutorials for your help";
$val1 = ltrim($str);
$val2 = trim($str);
$val3 = rtrim($str);
.

How can you get web browser’s details using PHP?

get_browser() function is used to retrieve the client browser details in PHP. This is a library function is PHP which looks up the browscap.ini file of the user and returns the capabilities of its browser.

Syntax:

get_browser(user_agent,return_array);

Example Usage:

$browserInfo = get_browser(null,True);
print_r($browserInfo);
.