PHP Interview Questions and Answers For Freshers
PHP Interview Questions and Answers For Freshers
freshers
Welcome !!!. In this section we are providing you some frequently
asked PHP Interview Questions which will help you to win
interview session easily. Candidates must read this section,Then by
heart the questions and answers. Also, review sample answers and
advice on how to answer these typical interview questions. PHP is
an important part of the web world, and every web developer
should have the basic knowledge in PHP.Common PHP interview
questions, which should help you become a best PHP codder. We
hope you find these questions useful. If you are an interviewer, Take
the time to read the common interview questions you will most
likely be asked.
1. What is PHP?
PHP is a server side scripting language commonly used for web
applications. PHP has many frameworks and cms for creating
websites.Even a non technical person can cretae sites using its
CMS.WordPress,osCommerce are the famus CMS of php.It is
also an object oriented programming language like java,Csharp etc.It is very eazy for learning
2. What is the use of "echo" in php?
It is used to print a data in the webpage, Example: <?php
echo 'Car insurance'; ?> , The following code print the text in
the webpage
3. How to include a file to a php page?
We can include a file using "include() " or "require()" function
with file path as its parameter.
4. What's the difference between include and require?
11.
eg : echo $_COOKIE["user"];
15.
How to create a session? How to set a value in
session ? How to Remove data from a session?
Create session : session_start();
Set value into session : $_SESSION['USER_ID']=1;
Remove data from a session : unset($_SESSION['USER_ID'];
16.
for,while,do while and foreach (NB: You should learn its usage)
17.
mysql_connect(servername,username,password);
18.
mysql_select_db($db_name);
19.
How to execute an sql query? How to fetch its
result ?
$my_qry = mysql_query("SELECT * FROM `users` WHERE
`u_id`='1'; ");
$result = mysql_fetch_array($my_qry);
echo $result['First_name'];
20.
23.
What is the difference between explode() and
split() functions?
Split function splits string into array by regular expression.
Explode splits a string into array by string.
24.
What is the use of mysql_real_escape_string()
function?
It is used to escapes special characters in a string for use in an
SQL statement
25.
Write down the code for save an uploaded file in
php.
if ($_FILES["file"]["error"] == 0)
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
26.
$filename = "/home/user/guest/newfile.txt";
$file = fopen( $filename, "w" );
if( $file == false )
{
echo ( "Error in opening new file" ); exit();
}
fwrite( $file, "This is a simple test\n" );
fclose( $file );
27.
How to strip whitespace (or other characters) from
the beginning and end of a string ?
The trim() function removes whitespaces or other predefined
characters from both sides of a string.
28.
35.
What is the difference between
mysql_fetch_array() and mysql_fetch_assoc() ?
mysql_fetch_assoc function Fetch a result row as an
associative array, Whilemysql_fetch_array() fetches an
associative array, a numeric array, or both
36.
41.
<input
MD5 PHP implements the MD5 hash algorithm using the md5
function,
eg : $encrypted_text = md5 ($msg);
mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher ,
string $key , string $data , string $mode [, string $iv ] );
Encrypts plaintext with given parameters
49.
51.
What is PEAR?