Escolar Documentos
Profissional Documentos
Cultura Documentos
An Overview of PHP
PHP earlier stood for Personal Home Pages, but now it stands for Hypertext Pre-processor. PHP is a server-side scripting language
that is used for building web pages and applications. This language includes many Frameworks and CMS for creating large
websites. Even a non-technical person can create web pages or apps using PHP CMS or PHP frameworks. We have just added
more questions in our question bank for PHP interview questions and answers for experienced.
CMS in PHP is built with the website manager in mind. All CMS makes it very simple to manage the website content. The business
owner can change information on the website without a problem. CMS like WordPress, Drupal, Drupal, Joomla, Magento, etc
If you are preparing for PHP interviews, you can read PHP interview questions for clarity and insight.
The framework in PHP usually does not have the default standard user interfaces, which makes CMS so user-friendly. In the
framework, developers can create an interface using the available library methods. CSS frameworks like SASS or Bootstrap can be
used with PHP frameworks to develop a site for the best user experience. Developers can develop responsive sites using these front
end frameworks. Frameworks like Laravel, CakePHP, CodeIgniter, YII, etc
Our biggest and updated question bank for Advanced PHP interview questions are one of the biggest question bank available
online.
Advantages of PHP
Open source
Robust functions
Centralized built-in database
Extensive community support
Disadvantages of PHP
Not very secure
Unable to manage a large number of apps
Unexpected bugs may appear
If you are looking for an opportunity to move ahead in your career as a PHP developer or if you are looking for PHP interview
questions and answers for experienced that can help you crack your interview.
suggest an answer
suggest an answer
suggest an answer
suggest an answer
Example
unlink('headbar.php');
unset(&variable);
suggest an answer
More interview Questions from PHP
OOPS INTERVIEW QUESTIONS
LARAVEL INTERVIEW QUESTIONS
WORDPRESS INTERVIEW QUESTIONS
YII INTERVIEW QUESTIONS
DRUPAL INTERVIEW QUESTIONS
JOOMLA INTERVIEW QUESTIONS
CAKEPHP INTERVIEW QUESTIONS
CODEIGNITER INTERVIEW QUESTIONS
YII 2 INTERVIEW QUESTIONS
LARAVEL 5 INTERVIEW QUESTIONS
ZEND FRAMEWORK INTERVIEW QUESTIONS
ZEND 2 FRAMEWORK INTERVIEW QUESTIONS
SYMFONY INTERVIEW QUESTIONS
MAGENTO INTERVIEW QUESTIONS
OPENCART INTERVIEW QUESTIONS
suggest an answer
suggest an answer
So here is a simple function in PHP to find the real IP address of the user’s machine.
Example
function getRealIpAddr()
if (!empty($_SERVER['HTTP_CLIENT_IP']))
$ip=$_SERVER['HTTP_CLIENT_IP'];
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
else
$ip=$_SERVER['REMOTE_ADDR'];
return $ip;
suggest an answer
Ques. 9. Difference between require() and require_once() in PHP? When can we use these functions?
require() and require_once() both are used for include PHP files into another PHP files. But the difference is with the help of
require() we can include the same file many times in a single page, but in case of require_once() we can call the same file
many times, but PHP includes that file only single time.
suggest an answer
GET POST
The GET method transfer data in The post method transfer form data by HTTP Headers. This POST method does not
the form of QUERY_STRING. Using have any restriction on data size to be sent. With POST method data can travel
GET it provides a $_GET associative within the form of ASCII as well as binary data. Using POST, it provides a $_POST
array to access data associative array to access data.
suggest an answer
Example
define('DB_NAME', 'bestInterviewQ')
suggest an answer
suggest an answer
nl2br()
trim()
str_replace()
str_word_count()
strlen()
strpos()
strstr()
strtolower()
strtoupper()
suggest an answer
Example
$target_dir = "upload/";
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
$uploadOk = 1;
} else {
$uploadOk = 0;
suggest an answer
Ques. 15. Explain the difference between session and cookies in PHP?
Session and Cookies both functions are used to store information. But the main difference between a session and a cookie
is that in case of session data is stored on the server but cookies stored data on the browsers.
Sessions are more secure than cookies because session stored information on servers. We can also turn off Cookies from
the browser.
Example
session_start();
//session variable
$_SESSION['user'] = 'BestInterviewQuestion.com';
session_destroy();
unset($_SESSION['user']);
Example of Cookies
$cookie_uame = "user";
//expire cookies
setcookie($cookie_uname,"",-3600);
suggest an answer
suggest an answer
Ques. 17. What is the difference between file_get_contents() and file_put_contents() in PHP?
PHP has multiple functions to handle files operations like read, write, create or delete a file or file contents.
1. file_put_contents():It is used to create a new file.
Syntax :
file_put_contents(file_name, contentstring, flag)
If file_name doesn't exist, the file is created with the contentstring content. Else, the existing file is override, unless the
FILE_APPEND flag is set.
2. file_get_contents(): It is used to read the contents of a text file.
file_get_contents($filename);
suggest an answer
Ques. 18. In PHP, how to redirect from one page to another page?
With the heal of the header(), we can redirect from one page to another in PHP.
Syntax :
header('location:index.php');
suggest an answer
multipart/form-data
text/plain
multipart/form-data
This is used to upload files to the server. It means no characters will be encoded. So It is used when a form requires binary
data, like the contents of a file, to be uploaded.
suggest an answer
suggest an answer
Ques. 21. How to add comments in PHP?
In PHP comments are two types.
01. Single line comments
02. Multi line comments
1. Single line comments: It is used comments a single line of code. It disables a line of PHP code. You have to add // or #
before the system.
2. Multi line comments: It is used to comment large blocks of code or writing multiple line comments. You have to add /*
before and */ after the system.
suggest an answer
suggest an answer
Ques. 23. How to get a total number of elements used in the array?
We can use the count() or size() function to get the number of elements or values in an array in PHP.
Example
$element = array("sunday","monday","tuesday");
echo count($element );
echo sizeof($element );
suggest an answer
Ques. 24. What is the difference between public, protected and private?
PHP has three access modifiers such as public, private and protected.
public scope of this variable or function is available from anywhere, other classes and instances of the object.
protected scope of this variable or function is available in all classes that extend the current class including the parent
class.
suggest an answer
Ques. 25. What is the difference between implode() and explode() in php?
explode() function breaks a string into an array, but the implode() function returns a series from the elements of an array.
Example : $arr = array("1","2","3","4","5");
$str = implode("-",$arr);
OUTPUT
1-2-3-4-5
$a = explode(" ",$array2 );
print_r ($a);
OUTPUT
suggest an answer
Ques. 26. What is the difference server side and browser side validation?
We need to add validation rules while making web forms. It is used because we need to take inputs from the user in the right
way like we need the right email address in the email input field. Some time user did not enter the correct address as we
aspect. That's why we need validation.
Validations can be applied on the server side or the client side.
In the Server Side Validation, the input submitted by the user is being sent to the server and validated using one of the server-
side scripting languages like ASP.Net, PHP, etc.
In the Client Side Validation, we can provide a better user experience by responding quickly at the browser level.
suggest an answer
Example
Create Cookie
$cookie_name = "username";
Update Cookie
$cookie_name = "username";
Delete Cookie
suggest an answer
These both are PHP inbuilt function which is used to open & close a file which is pointed file pointer.
1. This method is used to open a file in PHP. This method is used to close a file in PHP. It returns true or
false on success or failure.
suggest an answer
On our website you will find industy's best PHP interview questions for 5 year experience .
suggest an answer
Ques. 30. How to get last inserted id after insert data from a table in mysql?
mysql_insert_id() is used to get last insert id. It is used after insert data query. It will work when id is enabled as AUTO
INCREMENT
suggest an answer
suggest an answer
suggest an answer
suggest an answer
suggest an answer
suggest an answer
Ques. 36. Please explain the difference between $var and $$var?
$$var is known as reference variable where $var is a normal variable.
suggest an answer
Ques. 37. Please explain the difference between isset() and empty()?
1. isset(): It returns TRUE if the variable exists and has a value other than NULL. It means variables assigned a "", 0, "0", or FALSE
are set.
2. empty(): It checks to see if a variable is empty. It interpreted as: "" (an empty string).
isset($var) && !empty($var)
suggest an answer
suggest an answer
Ques. 39. What are the __construct() and __destruct() methods in a PHP class?
Constructor and a Destructor both are special functions which are automatically called when an object is created and
destroyed.
Example
class Animal
{
$this->name = $name;
suggest an answer
"://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
suggest an answer
Example
<?php require('footer.php') ?>
suggest an answer
suggest an answer
error_reporting(E_ALL);
ini_set('display_errors', '1');
suggest an answer
suggest an answer
Example
trait HelloWorld
class MyWorld
use HelloWorld;
suggest an answer
Ques. 46. What is inheritance in PHP? How many types of inheritance supports PHP?
Inheritance has three types, are given below.
Single inheritance
Multiple inheritance
Multilevel inheritance
But PHP supports only single inheritance, where only one class can be derived from a single parent class. We can do the
same thing like multiple inheritance by using interfaces.
suggest an answer
Ques. 47. How to download files from an external server with code in PHP?
Example
$ch = curl_init();
$source = "http://abc.com/logo.jpg";
curl_close ($ch);
$destination = "/images/newlogo.jpg";
fputs($file, $data);
fclose($file);
$url = 'http://abc.com/logo.jpg';
$img = '/images/flower.jpg';
file_put_contents($img, file_get_contents($url));
suggest an answer
suggest an answer
We have covered all levels of PHP interview question for fresher - basic and advanced levels.
suggest an answer
Example :
class phpClass {
echo 'Test';
}
}
suggest an answer
Ques. 51. What are the final class and final method?
Its properties cannot be declared final, only classes and methods may be declared as final. If the class or method defined as
final, then it cannot be extended.
Example
protected $numPages;
$this->_autor = $autor;
$this->numPages = $pages;
return $this->numPages;
suggest an answer
Ques. 52. Please write a query to find the 2nd highest salary of an employee from the employee table?
You can use this SELECT MAX(salary) FROM employee WHERE Salary NOT IN ( SELECT Max(Salary) FROM employee); Query to find
the 2nd highest salary of the employee.
suggest an answer
suggest an answer
Ques. 54. How to get a total number of rows available in the table?
COUNT(*) is used to count the number of rows in the table.
suggest an answer
suggest an answer
suggest an answer
suggest an answer
suggest an answer
Example
Namespace MyAPP;
function output() {
echo 'IOS!';
namespace MyNeWAPP;
function output(){
echo 'RSS!';
suggest an answer
suggest an answer
Example
$ch = curl_init("https://www.bestinterviewquestion.com/");
curl_exec($ch);
curl_close($ch);
fclose($fp);
suggest an answer
$revnum = 0;
suggest an answer
return 0;
return 1;
$a = IsPrime(3);
if ($a==0)
else
suggest an answer
Example
function getTableOfGivenNumber($number) {
echo $i*$number;
getTableOfGivenNumber(5);
suggest an answer
suggest an answer
Ques. 66. What is the difference between abstract class and interface in php?
Many differences occur between the interface and abstract class in php.
Abstract methods can declare with protected, public, private. But in case of Interface methods stated with the public.
Abstract classes can have method stubs, constants, members, and defined processes, but interfaces can only have
constants and methods stubs.
Abstract classes do not support multiple inheritance but interface support this.
Abstract classes can contain constructors, but the interface does not support constructors.
suggest an answer
suggest an answer
This is a good question concerning PHP programming interview questions and answers for freshers.
suggest an answer
suggest an answer
RewriteEngine On
RewriteCond %{HTTPS} on
suggest an answer
suggest an answer
Ques. 73. What is the best way to avoid email sent through PHP getting into the spam folder?
Sending mail using the PHP mail function with minimum parameters we tend to should use headers like MIME-version,
Content-type, reply address, from address, etc. to avoid this case
Did not use correct SMTP mail script like PHPmailer.
Should not use website link in mail content.
suggest an answer
suggest an answer
suggest an answer
Example
$servername = "your hostname";
// Create connection
// Check connection
if ($conn->connect_error) {
echo "Connected";
suggest an answer
Latest Blogs
1 month ago
1 month ago
Why Bootstrap is the Best UI Design Tool
1 month ago
Featured Category
Web Testing /
Development Frontend /UI Database Design Mobile App Government HR QA
Our Categories
Website development
HR Interview Questions
SEO Interview Questions
Database Interview Questions
Frontend / UI Interview Question
Testing / QA Interview Questions
Mobile App Interview Questions
Designing Interview Questions
Govt. jobs Interview Questions
Newsletter
Stay update with our latest interview questions